The Effortless Way to Integrate Facebook Login and Grow Your Android App’s Registration by 40%

You know that Android is an open-source platform. This means you can easily contribute to the Android community by developing apps.


How to integrate facebook login in your native Android app.

The recent study revealed that three out of four people leave a long registration process. This situation is even more critical in the mobile app world. Because, a mobile user with the on-screen keyboard is most likely to leave an app, rather than troubling him/herself of going through the registration process. That is why the Android apps with Facebook login are the winners.

Let’s get started.


#1: Create a New Project

Go to File menu in your Android Studio, click on new and you’ll see an option of the project, click on it.

#2: Get Key Hash Value

After you add facebook library, you’ll need to get key hash value. So, in order to get this value, write the below code in ‘oncreate()’ method of ‘’.

try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {

#3: Import Gradle

Next, you’ll need to import Facebook Android SDK grade shown as below.

compile ‘’

#4: Create Facebook App ID

To do this, go to facebook developer site (

After developer facebook login, click on the ‘Add a New App’.


Now, enter your details and click on ‘Create App ID’.


Once you create your app, go to application dashboard and copy the ‘App ID’.


After you get your App ID, it’s time to register package and activity. Go to the settings from left-side menu and click on ‘Add Platform’.


Now, select ‘Android platform’.


Here, register your application package name and activity that use facebook sharing. And, add the key hash value that we explained in Step: 2.


#5: Add App ID

Add the App ID in the Strings.xml file of your application.

<string name="app_id">your app_id</string>

#6: Add below code to AndroidManifest.xml

android:n<uses-permission android:name="android.permission.INTERNET">ame="com.facebook.FacebookActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
android:value="@string/app_id" />

#7: Code to integrate Facebook Login

CallbackManager callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile", "email", "user_birthday"));
new FacebookCallback<LoginResult>() {

public void onSuccess(final LoginResult loginResult)

final String accessToken = loginResult.getAccessToken().getToken();
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
public void onCompleted(JSONObject object, GraphResponse response)

Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,gender,email,birthday");
public void onCancel() {
public void onError(FacebookException exception)
Log.e("ERROR", exception.toString());

#8: Override below

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

So, by implementing the above code, you can add a ‘sign in with Facebook’ button in your Android application.

You can find a copy of the same code on GitHub here.

Nowadays, most companies including Big enterprises and Startups always prefer to integrate Facebook login in their registration pages. So, if you too want to grow your app audience and registration rates, you can simply hire Space-O Technologies, which is a leading Mobile App Development Company and we have worked with world’s finest startups to turn their ideas into an App. You can check our portfolio here for more details.


Have an App Idea?

Get your free consultation now

Leave a Reply

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

Get Your Free Quote