Group Services: Technology Consulting
phone +91-9999-283-283/9540-283-283
Facebook Logo

Android Facebook Integration

Facebook is an online social media and social networking service. Users can post comments, share photographs and links to news or other interesting content on the Web, play games, chat live, and even stream live video. Shared content can be made publicly accessible, or it can be shared only among a select group of friends or family, or with a single person. Facebook is also available as Android App.

In this blog, we will be discussing how can we integrate Android Apps with Facebook. We will be using a Facebook Login button to make the user enter our App using their facebook credentials. Developers can extract all the available information that the fb API provides. Steps to develop this can be summarized below -

Used Concepts & Used Version: (Version of Android SDK, Facebook SDK)

We will be using Facebook's SDK here which is provided by Facebook's Developers website.

Now, let us begin the development...

1.Create a new app ID on Facebook website.

2.Click on import facebook sdk and Include the dependencies required for integration in your project.

Add Dependency to app module also.

Run ‘Sync Gradle’ after you add the dependencies.

3.Provide information about your project- package and Default Activity Class.

In the next Dialog , click on 'Use this package name' as we are developing for testing purposes and will not be working on an app on Google Play.

4. Downloading Open SSL.

Visit the link - - to download the openssl. Open SSL is open source and a software library to be used in applications that need to secure communications over computer networks against eavesdropping or need to ascertain the identity of the party at the other end.

5. Generating Key Hashes

Go to your computer's command Prompt to generate the Key hashes. You will require below commands for generating key hashes.

Enter the Key Hashes into the Key Hashes field.

6. Enable Single Sign On in the next step.

Go to your app's String's file in the value folder. Enter your app id there as one the strings.

7. Making changes in Manifest file.

8. Handling the Login button

Add a Login button and Logout button for the app in the layout. Login button is provided by the Facebook SDK.

Below is the MainActivity which handles the login button. We use a callBackhandler to be called when user presses the Login button.the callBack is registered within the onCreate method and called on Login button. The callback gets the user's identity confirmed from Facebook and calls the nextActivity method while providing the profile as the argument. In the nextActivity method , profile is used to fetch the details of the user and provided to an Intent(which is to be fired to take user to next Activity - Main2Activity.class).

Main2Activity.class fetches the data from the intent and displays it on its layout. We are showing user's name and display picture here. For downloading the image, we are using DownloadImage.class which is extending AsyncTask.

Layout for Main2Activity.class


9. Output of the App.

Below are the screenshots from the app after development.