In this tutorial I’m going to explain how we can integrate Facebook SDK into Android application and customize sharing dialog based on your need. Following figure shows what we want to do. Click here to download source code of this sample project.
Requirements:
- You need Facebook account and then go to https://developers.facebook.com/apps and create new application. App Id will be generated automatically and you need to add it into your code. Also, you need to add key hash in its filed. But you should generate it based on your key store. I’ll tell you how get it later in this code.

- Download Facebook SDK. Then add it to Eclipse. Right click on it and go to Properties/Android and check “is library” from library section. Now this project acts as library for your project.
- In order to get “Key Hash” you need to activate Facebook log. So, open src directory and open com.facebook.android. open Util.java class. Find
private static boolean ENABLE_LOG = false;
and change it to
private static boolean ENABLE_LOG = true;Now, you can see Facebook logs in your Logcat. For security reasons its better to change it to false after getting key hash. You are needed to copy/past key hash into its field in Facebook application page.
- Create new project in Eclipse. Then right click on this project. Go to Properties/Android and from right panel by clicking “Add” button, add Facebook SDK to your project.
- SDK is not the only thing for sharing your posts. Create new package (I named it com.socialnetworks.facebook) and add all files into this package. These classes are handlers that you need to use them.
- Finally, based on my sample code you can develop your code. It is self description and simple enough to understand it. The only thing the maybe needs to be explained is postFacebookMessage() in lines 169-199. Around middle of June, Facebook changed posting process and in this new change developers are need to create a JSON object and add all titles, links and images into this object. Lines 173-194 are showing this process.

You must log in to post a comment.