Facebook Android SDK 4.5 LikeView not working - android

I am trying to integrate latest facebook android sdk(v 4.5) Like button. This is what I have put in my facebook_layout.xml
<com.facebook.share.widget.LikeView
android:layout_marginTop="30dp"
android:id="#+id/like_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</com.facebook.share.widget.LikeView>
And I have a fragment where I am putting this like view onCreate method to
initialize the view
LikeView likeView = (LikeView)facebookview.findViewById(R.id.like_view);
likeView.setEnabled(true);
likeView.setLikeViewStyle(LikeView.Style.BOX_COUNT);
likeView.setObjectIdAndType(
"https://www.facebook.com/FacebookDevelopers",
LikeView.ObjectType.PAGE);
Apart from this I have also put my app id in AndroidManifest.xml as mentioned here
But I am still not able to get the like to work. When I Click on the like button it just opens up a black facebook activity and for few seconds and closes it, and there are no likes happening on this page or the same page i have created for testing.

I have resolved this issue by adding my facebook user as a Tester/Developer to my facebook android App.
Reference: https://developers.facebook.com/docs/apps/security
Note: you can set the error listener to the object of LikeView for the better understanding of what error you are getting.
likeView.setOnErrorListener(new LikeView.OnErrorListener() {
#Override
public void onError(FacebookException e) {
Log.e(TAG, e.getMessage(), e);
}
});

Related

Add Event Handler to ImageButton

I am developing an Android app that has an ImageButton in it, and I need to add an event handler to it. In my attempt to do this, I have added a new function to the .java file that Android Studio creates when you make new project that looks like this:
public void tapImageButton(ImageButton myImgBtn) {
// Code that does stuff will come later on.
}
After doing this, trying to set the onClick proerty does not show the function, and trying to enter it manually causes the app to crash when I test it.
You must have View as a parameter of method that you wish to call, while bind click event through layout file.
Try this:
public void tapImageButton(View view) {
// Code that does stuff will come later on.
Toast.makeText(this, "clicked !!", Toast.LENGTH_SHORT).show();
}
In xml:
...
android:onClick="tapImageButton"
...
I am not very familiar with android studio but when i tried making a button and having it do something on click i first added the android:onClick = "some_method_name" to the XML that makes the design of the app. I first added the name in the onClick and then i clicked on the name. When the little light bulb icon shows up the arrow next to it give the option of creating a method with that method name that you just wrote. once you create it then you add the code of whatever you want to happen when you click. Hope it works.
For Example, This is the XML:
<Button
android:id="#+id/playButton"
android:text="#string/play"
android:textSize="25sp"
android:background="#0099FF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:onClick="startGame" />
This is the Java:
public void startGame(View view) {
Intent intent = new Intent(this,GameActivity.class);
startActivity(intent);
}

Google Play Games achievement unlocked popup not showing

I'm unlocking achievement using this simple method from developers docs:
Games.Achievements.unlock(getApiClient(), "my_achievement_id");
Achievement unlocks, but no popup shows up. There is also no popup when logged in to Google Play Games - which is connected.
Just add a view to the layouts you want to display achievements on like this:
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
When you have your layout ready you neet to execute this inside your Activity or Fragment:
Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup));
You have to be sure, that your GoogleApiClient is connected though, otherwise your app will crash.
<FrameLayout
android:id="#+id/gps_popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
This is the same in Jacek Kwiecień answer
GamesClient gamesClient = Games.getGamesClient(MainActivity.this, GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));
This changed because setViewForPopups with 2 parameters is deprecated.
Jacek and user3782779 answers didn't work for me, I had to do the following:
GamesClient gamesClient = Games.getGamesClient(this, GoogleSignIn.getLastSignedInAccount(this));
gamesClient.setViewForPopups(findViewById(android.R.id.content));
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
Had the same problem. I have solved it by adding icon to the achievement. I am not kidding, it is really strange but it started to work after that. Please note that I am talking about not published project, I was just testing my app and wondering what is going on.
The ONLY view that worked for my case of having multiple activities was:
activity.window.decorView.findViewById(android.R.id.content)
I had the same problem with the achievement popup. The "Welcome Back" popup was showing correctly by just using my own View, but once I started opening other screens where I wanted to show the achievement unlocked popup, it was not working. The only thing that ended up working was using the content view from the decorView
val gamesClient = Games.getGamesClient(activity, googleSignInAccount)
gamesClient.setGravityForPopups(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
gamesClient.setViewForPopups(activity.window.decorView.findViewById(android.R.id.content))
You can call this code from any new activity you open and the pop-up will show up there as soon as you unlock your achievements.

Facebook SDK button in android studio

I am trying to add a facebook login to my app, in addition to my custom log in.
I added facebook sdk as a module but when I try to add the Facebook Connect button I get an error.
Error:
Rendering Problems The following classes could not be instantiated:
- com.facebook.widget.LoginButton (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F040001.
Code:
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
First it is possible problem of the Eclipse, you just need to rester environment. To see if help.
Secondary, try to use this code snippet to solve problem.
if (isInEditMode())
{
//do something else, as getResources() is not valid.
} else {
//you can use getResources()
String mystring = getResources().getString(R.string.mystring);
}

Like Blog Post Facebook Button

I have a blog which shows a Facebook like button under every post.
I want to add that button, which upon click, just like that blog post, to an android app. Is that possible? If yes, then how?
Do I have to use Facebook SDK?
This is how the button is displayed in the blog.
<iframe allowTransparency='true' expr:src='"http://www.facebook.com/plugins/like.php?href=" + data:post.canonicalUrl+"&send=false&layout=button_count&show_faces=false&width=90&action=like&font=arial&colorscheme=light&height=21"' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:90px; height:21px;'/>
Try this : It's working for me
<com.facebook.widget.LikeView
android:id="#+id/like"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Like"
/>
And add following code in your android class file:
LikeView likeView = (LikeView) findViewById(R.id.like);
likeView.setObjectId("Your URL);

How can i Integrating the AirPush Ads in my android application?

i want to add the AirPush Ads in my android application. I have worked read the full documentation from the http://www.airpush.com/publishers/publishers/downloadsdk/ and this pdf file download pdf for airpush sdk
Now i have two queries:
We have to give the app url either of the android market or some other when we create new app using the airpush sdk. So how can we give that url like 1st upload the app without that airpush integration and get the url of the app and then again upload with the airpush integration.
And the 2nd thing is we have to just give that app id, app key and package name in the manifest and add the jar file in lib. and rest some code which i shown below in that activity where we want to show these Ads. Am i wright ??
public class AirTestActivity extends Activity {
Airpush airpush;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// create Airpush constructor.
airpush = new Airpush(this);
airpush.startSmartWallAd(); //launch smart wall on App start
// start Dialog Ad
// airpush.startDialogAd();
// start AppWall ad
// airpush.startAppWall();
// start Landing Page
// airpush.startLandingPageAd();
airpush.startPushNotification(true);
// start icon ad.
airpush.startIconAd();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
//use smart wall on app exit.
// airpush.startSmartWallAd();
}
return super.onKeyDown(keyCode, event);
}
}
Is it necessary to add the layout with textview and image view in the layouts like below
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_centerHorizontal="true" >
</ImageView>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textAppearance="#android:style/TextAppearance.StatusBar.EventContent"
android:textSize="11dp" />
Anything else we have to do for that. Please guide me
Regarding #1 : You just need to have the package name of your application to construct market url. for example com.myapp.pack. So your app's market url will look like:
https://play.google.com/store/apps/details?id=com.myapp.pack.
In case if you change your app's package name you can edit it in edit app section of Airpush anytime.
Regarding #2 : Yes, thats the correct way to initialise Airpush.
Regarding #3 : The airpush_notify.xml is required for BannerPush ads.
Lastly the jar with your package name is the correct one to implement. Airpush360.jar is the sample jar provided with the Airtest app. IN case of any queries or confusions,please go through the implementation document provided on download sdk page or drop an email to support#airpush.com.

Categories

Resources