Table of Contents
What is Facebook Integration?
The Facebook SDK for Android enables people to sign in to 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.
In this blog, we will learn about how to integrate the Facebook login feature into the Android application. In some situations, we will need the app user to log in to the android app for further processing. Generally, Facebook Login and Google Login are used in most Applications.
Steps to Integrate Facebook into Android Application:
- First, create a new project in the android studio and name it “MySocialapp”.
- Now, go to the Facebook Developer console and create a new App. Follow the below link to log in and create a new app. https://developers.facebook.com/
You will find this screen

Now click on Log In and Log In with your Developer account on Facebook.
After successfully Logging In, you will find this below screen where you have to click on магазин постельного белья My Apps from the menu bar and click on Create App or Go to Docs>> Facebook Login>>Android. Select the newly created app from the ‘Select an App’ section in the document.

Then Create A New App ID

Give a proper name, Display Name and Your Email-id.

Now after clicking on Android, you will find this below screen

Find your newly created app and select it from the Dropdown list.

The next step is adding the Facebook SDK to Android Studio Project. Open MySocialapp >> Gradle Scripts >> build.Gradle (Project) and add these libraries in buildscript>>repositories.

In your project open MySocialapp>>Gradle Scripts>> build.Gradle (Module App) and add the following implementation statements to the dependencies section.

For this application, we need a circle image view to display the Facebook profile pic тактичні рукавиці без пальців. An image loading library to load an image into Image view from URL.
In this project, we use the Glide image loading library and a third-party Circle Image View library. Add the dependency for using them as given below. Here I have used ready GitHub libraries.

From the Facebook Login Configuration page, copy the facebook_app_id and fb_login_protocol_scheme string resources. Add it to the Strings.xml file in the android studio project.

Open string.xml

- Open the AndroidManifest.Xml file and add the following statements to it.
Internet Permission.

Meta-data element that mansion your app Id.

Facebook Activity and intent filter for Chrome Custom Tabs.

Associate Your Package Name and Default Class with Your App.

- Provide development and Release Key hashes for your App. For generating the key hash you need a key tool that is available with java SDK, your release or debugs key-store and in the windows platform, you need the OpenSSL library.
- Download OpenSSL – for – windows from Google code Archive. You will find this below-mentioned screen. I have downloaded OpenSSL-0.9.8e_X64.zip.

Extract the folder into C Drive and copy the path of that folder.
C:openssl
Now, find your Java SDK path. In my PC this is a path for Java bin folder.
C:Program FilesJavajdk1.8.0_144bin
Now, find debug. keystore path from your This PC and copy it.
In Users>>User_Name>>.android>>debug.keystore, Here this is the path in my PC.
C:UsersHINAL.android
Now Go to “C:Program FilesJavajdk1.8.0_144bin” bin folder and start the command prompt.


Search for CMD

Copy the path from Step 6 on developers.facebook.com

(keytool -exportcert -alias androiddebugkey-Keystore (Your Keystore path)debug.keystore | (Your OpenSSL path)openssl sha1 -binary | (Your OpenSSL path)openssl base64)
(Your Keystore path) in place of this add your debug.keystore path.
(Your OpenSSL path) in place of this add your OpenSSL path.
After adding all paths my path will be:
keytool -exportcert -alias androiddebugkey -Keystore “C:UsersHINAL.androiddebug.keystore” | “C:opensslbinopenssl” sha1 -binary | “C:opensslbinopenssl” base64
Add this path into a command prompt and get hash key.
Add the hash key into step 6 and save it.

Now, Enable Single Sign-On for your App.

- Add this code to your activity_main.xml file


I have added static values to show this Component. Now the screen will look like this.

- Add this code to your MainActivity.java file.



- Request email and public profile permissions on Facebook Login Button.
- To handle login response, create a CallbackManager object by using Factory.create
- To respond to the login result we register a callback with LoginButton.
- If the login succeeds, the LoginResult parameter of the onSuccess() callback method has a new AccessToken and the most recently granted and denied permissions.
- In this example for getting a login response ліхтар кемпінговий, we are not going to use the callback methods with LoginButton, instead, we use the AccessTokenTracker class.
- Override the onActivityResult method to pass the login result to the LoginManager using the callback manager.
- For checking the Login status when the app load, call the getCurrentAccessToken() method using AccessToken class, and if the method return null means the user logged out.
- To read user information from AccessToken, we use Graph API. Facebook uses a special API called Graph API to read and write information on the Facebook platform emerson gear. Graph API brings the result in the form of a JSON object or JSON array.
Output:
Login Screen:
Logged-In Screen:
Log Out Screen:
Logged Out Screen:




Conclusion
With the end of this tutorial, we hope we were able to fulfill our purpose of helping you to integrate Facebook login feature in an Android application. We tried to explain the whole process with the help of screenshots with proper descriptions плитоноска койот. If you follow the above steps without any error, you will be able to integrate Facebook login into your Android application successfully.
If you still have any doubts, don’t worry. You can always get in touch with us for any kind of query.
Recommended Reading:
AboutSiddharth Patel
Related Posts
Highlights: Why are Top 20+ Brands Using PWA to Improve Their Business Website?
Table of Contents “Technology Has Become Appallingly Obvious, and Has Changed our Lives Today”Top Reasons to...
Online Medicine Delivery App: Best Solution to Help Your Pharmacy Business in 2021
As we know, every business is going online these days, and the eCommerce business has dominated the industry in the current...