Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Updated 14 December 2016
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:
LoginManager
onActivityResult
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.+’ }
dependencies {
        compile ‘com.facebook.android:facebook-android-sdk:4.+’
}
2. Initialize  FacebookSdk and setup facebook’s CallbackManager
FacebookSdk
CallbackManager
If you use the LoginButton in a fragment, you need to set the fragment on the button as shown by calling setFragment.
LoginButton
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:
FacebookSdk.initialize
CallbackManager.Factory.create
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:
onCreate()
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.
LoginResult
AccessToken
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.
registerCallback
AccessTokenTracker
Then in onActivityResult() forward the login results to the callbackManager created in onCreate():
onActivityResult()
callbackManager
Note: Every activity and fragment that you integrate with the FacebookSDK Login or Share should forward onActivityResult to the callbackManager.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.