How to Use Facebook SDK for Android?

Nowadays, social media integration has become one of the most effective means of making an app successful. Whether it’s your social app or your business app, integrating it with a highly popular social network is perhaps the best method of reaching out to a wider group of the targeted audience. Amongst the wide count of social networking websites available over the internet, Facebook has been holding the topmost position. Being the supreme social network in the world, Facebook has also found its niche in the world of social SDKs. If you’re an Android app developer, then you’d definitely be familiar with the benefits of getting started with Facebook SDK on Android. If you aren’t, then don’t worry because this blog will tell you all. Here, I’ve covered some vital aspects related to the use of Facebook SDK during Android app development projects.

Facebook SDK for Android

Integrating an Android app with Facebook’s platform is something that requires a great deal of patience and understanding. While allowing you to do this, Facebook SDK for Android also renders support for reading and writing to the Facebook APIs, log in with Facebook authentication and support for a set of UI elements including dialogs, pickers, etc.

Facebook SDK for Android

And now, the steps involved in setting up Facebook SDK for Android. Hereunder is the Facebook integration in an Android step by step.

1. Install software

As the very first step, ensure that you have all the required software programs installed on your system. These include Android 2.2(API 8) platform, Facebook SDK for Android, API on Emulator( this is optional and applicable only in case you’re inclined to use the Android emulator during app development).

2. Create an app on Facebook

Before proceeding ahead to the integration of Facebook SDK into your Android app, you need to create a separate Facebook app on your Facebook developer console itself. For this, simply visit the Facebook developer console and create the new Facebook application. Once you’re done with creating the new app, you’ll receive a unique app id that would allow your app to stand out from the crowd.

3. Create an Android app

After having created a Facebook app in your Facebook developer console, gear up for importing Facebook SDK for Android to your workspace. One of the best ways of attaching the Facebook SDK is to add it as an Android library by navigating to the project’s unique properties.

4. Insert code given below

Insert the below-mentioned code before the </application> tag in your Android application manifest file. Here, also ensure that you are using your own AppID that was obtained post the creation of an app using the Facebook developer console(this has already been explained above).

<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />

In addition to the above code, also add the required tags in the manifest file, followed by adding a meta tag in the application id and declaring Facebook’s Login Activity as explained in the below code snippet:

<uses-permission android:name="android.permission.INTERNET"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="1509004692340262"/>
<activity android:name="com.facebook.LoginActivity"/>

5. Give required permissions

Finally, open a session and inquire for the user’s first name. Here, the Facebook SDK for Android will automatically prompt the user to log in and accept all the basic permissions with the help of login activity. The code related to this task is shown below:

private void openFacebookSession() {
// Open a Facebook session to get the user's name
Session.openActiveSession(this, true, new Session.StatusCallback() {
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
// Response Callback
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(;
welcome.setText("Welcome " + user.getFirstName() + "!");

So, with that, you’re done. Well, if your Android application requires a user to log in, then it is highly recommended to integrate the same with Facebook SDK. The reason for this being that it will not only make the login process smoother but will even allow you to monetize your application in the best possible manner.

Wrapping up

Here’s hoping all the information covered in this blog would have served as a handy guide for all of you who’re thinking about equipping your Android application with some incredibly amazing features of the very popular and trendy Facebook social networking website. So, make a move and follow the above steps to attain your goal.

Leave a Comment

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