Like Button for Android Apps

This document refers to the Android SDK v3. For implementing the Like button with the new Android SDK v4 please see Sharing for Android docs.

The Like button is the quickest way for people to share content with their friends. A single click on the Like button will 'like' pieces of content from your app and share them on Facebook.

The Like button can be used to like a Facebook Page or any Open Graph object and can be referenced by URL or ID. Here's what the code looks like.

In your Activity or Fragment's onCreate method, use either the UiLifecycleHelper or call Settings.sdkInitialize:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    uiHelper = new UiLifecycleHelper(this, callback);
    // if you don't want to use the UiLifecycleHelper, call sdkInitialize instead
    // Settings.sdkInitialize(this);
    ...

Then set the object ID for the Like button as a a URL or a Facebook ID:

LikeView likeView = (LikeView) findViewById(R.id.like_view);
likeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");

Then call the UiLifecycleHelper again in your onActivityResult method

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

    uiHelper.onActivityResult(requestCode, resultCode, data, null);
    // if you don't use the UiLifecycleHelper, call handleOnActivityResult on the LikeView instead
    // LikeView.handleOnActivityResult(this, requestCode, resultCode, data);
    ...

This is what the button looks like in your app:

Review

Please note that you will have to submit your integration of the Like button for review with the Status and Review tab in the App Dashboard (see the Review Guidelines). You will also need to follow our Platform Policy 4.14. If you use the Like button on iOS or Android, don’t collect or use any information from it.

Prerequisites

Before you can use the Like button, you will need:

  • Your environment set up.
  • A Facebook app properly configured and linked to your Android app.
  • The Facebook SDK added to your project.

If you haven't done this and need help doing so, you can follow our getting started guide.

Using the Like Button

Add the Like button to your view like you would any other View.

When the Like button is tapped, it will switch to the Facebook app and present the Like Dialog. If the Facebook app is not installed, it will use an in-app WebView instead. Here is what the Like Dialog looks like:

When one of the buttons is tapped, it will return to your app and update the state of the like button along with the like count and/or sentence, if present. The BETA banner will be present until your app has been approved to use the Native Like Button feature.

If the person has provided publish_actions permission to your app, the Like button will update immediately and perform the action from your app using the og.likes API for OG objects. Page likes will always use the Like Dialog.

If you do not use Facebook Login the Like button will always open the Like Dialog to perform the like and confirm the action.

Settings

Please see the documentation for the LikeView for more information on what you can set on the view.