Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook SDK v4 LikeView issue

I'm trying to implement the Facebook "Like Button" in my Android app. Before I was using the Facebook SDK v3 where you would set up the LikeView and then call likeView.handleOnActivityResult(context, requestCode, resultCode, data) inside of onActivityResult(); This would change the button so that after the page was "liked" it would show "Liked" and the number of people that also like the page.

Now, I'm using the Facebook SDK v4 because v3 is now deprecated. In this version, I do not see any documentation or anyway to have this same type of functionality for the "like" button. It no longer has the likeView.handlePnActivityResult method that v3 had. Now when the user hits the "like" button and likes the page, it doesn't change the state of the button.

Does anyone know how to solve this issue so that it will have the same functionality as the LikeView in the Facebook SDK v3?

Here is the code of what I'm doing:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Initialize FaceBook SDK
    FacebookSdk.sdkInitialize(this);

    setContentView(R.layout.activity_about);

    // Set up ActionBar
    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    terms = (LinearLayout) findViewById(R.id.terms_holder);
    privacyPolicy = (LinearLayout) findViewById(R.id.privacy_policy_holder);
    share = (LinearLayout) findViewById(R.id.social_media_holder);
    environmentButton = (Button) findViewById(R.id.environment_change);
    likeView = (LikeView) findViewById(R.id.like_view);

    likeView.setObjectIdAndType("##############", LikeView.ObjectType.PAGE);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // In the old Facebook SDK this is where it would change the like button to "liked 2,038" but this code is deprecated now apparently
    // likeView.handleOnActivityResult(this, requestCode, resultCode, data);
}

And here is my XML:

<LinearLayout
android:id="@+id/social_media_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="onClick" >


<com.facebook.share.widget.LikeView
    android:id="@+id/like_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp" />           


<TextView
    android:id="@+id/post_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp"
    android:text="@string/post_about_us"
    android:textSize="20dp"
    android:textColor="@color/dark_grey" />

like image 740
Sloganho Avatar asked Apr 17 '15 17:04

Sloganho


1 Answers

Guardanis's answer is correct (Question's comment section). But this is the code for it ( I used).

in onCreate(...)

callbackManager = CallbackManager.Factory.create();

in onActivityResult(...)

 callbackManager.onActivityResult(requestCode, resultCode, data);
like image 158
kalan nawarathne Avatar answered Sep 29 '22 17:09

kalan nawarathne