Skip to content

Instantly share code, notes, and snippets.

@Abdelsattar
Created July 28, 2017 22:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abdelsattar/195e44bfe46f899883ace383f69f2a35 to your computer and use it in GitHub Desktop.
Save Abdelsattar/195e44bfe46f899883ace383f69f2a35 to your computer and use it in GitHub Desktop.
this is the method that will generate for you the key hash of your machine to add it to your facebook app page on developer
// will generate key hash for android for facebook
public String printKeyHash() {
PackageInfo packageInfo;
String key = null;
try {
//getting application package name, as defined in manifest
String packageName = this.getApplicationContext().getPackageName();
//Retriving package info
packageInfo = this.getPackageManager().getPackageInfo(packageName,
PackageManager.GET_SIGNATURES);
Log.e("Package Name=", this.getApplicationContext().getPackageName());
for (android.content.pm.Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
key = new String(Base64.encode(md.digest(), 0));
// String key = new String(Base64.encodeBytes(md.digest()));
Log.e("Key Hash =", key);
}
} catch (PackageManager.NameNotFoundException e1) {
Log.e("Name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("No such an algorithm", e.toString());
} catch (Exception e) {
Log.e("Exception", e.toString());
}
return key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment