Code Explosion

Code That Explodes Conventions (In daily life as a programmer I meet problems. This blog where I record them (and more importantly their solutions) so that I can dig them in the future.)

Add your app’s signature to the Facebook App Settings (Alternative Approach)

While developing android apps for Facebook, Facebook requires additional layer of security for mobile apps in the form an application signature. Using keytool that comes with Java JDK, I found difficulties; I couldn’t make it somehow. But I found way to get the hash key. Here is the alternative way to get the hash key.


import android.content.Context;
import android.util.Base64;
import android.util.Log;

public class Util {
private Context context;

public Util(Context context) {
this.context = context;

public void genHashKeyForFacebook() {
PackageInfo info;
try {
info = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;

md = MessageDigest.getInstance("SHA1");
String hash = new String(Base64.encode(md.digest(), 0));
Log.e("hash key", hash);
} catch (NameNotFoundException e) {
Log.e("name not found", e.toString());

catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());

Call this method genHashKeyForFacebook() from your activity; you will find the hash key in your LogCat verbose.

app's signature

About these ads

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


This entry was posted on March 17, 2012 by in Android, facebook, Tips and tagged .

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 346 other followers


  • SVG Compressed
    My recently published Kindle book, SVG Compressed, has received some great reviews already. 4 reviews with 5 stars. Not a bad start, but this is also my longest book so far, and it is available for only $0.99 on Amazon, so you get a lot for the money!
  • jQuery Compressed - 2nd Edition
    I have updated my Kindle book, jQuery Compressed 2nd edition, to be compatible with jQuery 1.11.0 and 2.1.0 .
  • jQuery Deferred Objects September 18, 2014
    Deferred objects in jQuery is how jQuery handles asynchronous code and callbacks. Deferred objects can be a bit complex when you first read about them, but once you understand them they are pretty simple, yet very useful. This tutorial explains how deferred objects in jQuery work.
  • Java volatile Keyword Tutorial September 15, 2014
    I have expanded my Java Concurrency tutorial with a tutorial on the Java volatile keyword which is used to assure that variables are read and written from and to main memory and not CPU / thread caches.
  • AngularJS $watch() , $digest() and $apply() August 26, 2014
    This new text in my AngularJS tutorial explains the $scope functions $watch() , $digest() and $apply(). These functions are the core of the AngularJS data binding system.

my tweets

  • This must be an interesting news : Legendary Larry Ellison steps down 7 hours ago
  • 2 days ago
  • দশটি বই আলাদা করা একটু বেশিই কঠিন। সুতরাং আমি ঠিক করলাম যে বই গুলো আমার ছোটবেলাকে চমকপ্রদ করেছে, চোখ ঢুলু... 2 weeks ago
  • A large system is one where you do not know that some of its component even exist. --Martin Odersky 1 month ago
  • reading After the Prophet: The Epic Story of the Shia-Sunni Split in Islam 1 month ago

Get every new post delivered to your Inbox.

Join 346 other followers