Login and Register via Facebook SDK in android application


The Facebook SDK for Android enables people to sign into your app with Facebook Login. When people log into your app with Facebook they can grant permissions to your app so you can retrieve information or perform actions on Facebook on their behalf.

There are two ways to implement Facebook login on Android:


There are other classes you use to add login to your app. The SDK includes:


Sample Activity to implement login using Facebook Android SDK.

1. Add Compile dependency in build.gradle:

dependencies {

         compile ‘com.facebook.android:facebook-android-sdk:4.+’


2. Initialize   FacebookSdk and setup facebook’s CallbackManager

If you use the LoginButton in a fragment, you need to set the fragment on the button as shown by calling setFragment.

You then need to call FacebookSdk.initialize to initialize the SDK, and then call CallbackManager.Factory.create to create a callback manager to handle login responses. Here’s an example of adding the callback in a fragment:

3. Register a Callback

To respond to a login result, you need to register a callback with either LoginManager or LoginButton. If you register the callback with LoginButton, don’t need to register the callback on Login manager.

You add the callback to your activity or fragment’s onCreate() method:

Layout used in the activity: main.xml

4. On successfull Login

If login succeeds, the LoginResult parameter has the new AccessToken, and the most recently granted or declined permissions.

You don’t need a registerCallback for login to succeed, you can choose to follow current access token changes with the AccessTokenTracker class described below.

Then in onActivityResult() forward the login results to the callbackManager created in onCreate():

Note: Every activity and fragment that you integrate with the FacebookSDK Login or Share should forward onActivityResult to the callbackManager.





. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.


We've bought a Shopware Extension which is a hybrid App, which we can now offer in the Google Play Store and the IOS App Store. I'am still impressed how fast and how sharp the support team leads us through every process of the App-Store clarification. Very fast and useful response.

Markus Walter

Markus Walter

Founder, Das Apartment Living

Talk to Sales


Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home