Skip to content

Instantly share code, notes, and snippets.

@saumya
Last active January 3, 2016 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saumya/8399013 to your computer and use it in GitHub Desktop.
Save saumya/8399013 to your computer and use it in GitHub Desktop.
Android : Print the HashKey required for working with native facebook SDK. On the android project, put this function(copy-paste) on the Main Activity class. Now call this.printFaceBookHash("com.saumya.myNativeApp"); Note: pass on the exact package name of your application. This will print the HashKey on the LogCat output of Eclipse. Not sure if …
private void printFaceBookHash(String packageName){
String mAppPackage = packageName;
try {
PackageInfo info = getPackageManager().getPackageInfo(
mAppPackage, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", "====================================================");
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
Log.d("KeyHash:", "====================================================");
}
} catch (NameNotFoundException e) {
Log.d("NameNotFoundException:", "====================================================");
e.printStackTrace();
Log.d("NameNotFoundException:", "====================================================");
} catch (NoSuchAlgorithmException e) {
Log.d("NoSuchAlgorithmException:", "====================================================");
e.printStackTrace();
Log.d("NoSuchAlgorithmException:", "====================================================");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment