Read complete story

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.

 

 

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close