Search code examples
androidfacebook-likefacebook-sdk-4.0facebook-sdk-3.0

How should I incorporate Like button in Android App with Facebook sdk 4?


I could only find this page in facebook documentation. There are links to it from other pages too. What bugs me is that it is title "Docs/Android SDK/Deprecated/Like Button (Android v3)". Is it really deprecated? If so, what's the v4 of doing it?

Update: I've accepted the answer because it links to the documentation ( Documentation: developers.facebook.com/docs/sharing/android) - I don't know how I missed it. However, this is not working for me as I expected :-( I will try to investigate further..


Solution

  • The way of doing that is inserting a LikeView into the layout this way:

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

    After that you just have to configure the like button as you wish, getting it from the layout like this:

    LikeView likeView = (LikeView) findViewById(R.id.like_view);
    likeView.setObjectIdAndType(
        "https://www.facebook.com/FacebookDevelopers",
        LikeView.ObjectType.PAGE);