Skip to content

Instantly share code, notes, and snippets.

@thedoapps
Last active August 29, 2015 14:07
Show Gist options
  • Save thedoapps/5e5e9472788bd00a957a to your computer and use it in GitHub Desktop.
Save thedoapps/5e5e9472788bd00a957a to your computer and use it in GitHub Desktop.
Generate key hash for Facebook - Android
/**generate key hash facebook**/
EditText txt_key_fb = (EditText) findViewById(R.id.txt_fb);
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), PackageManager.GET_SIGNATURES);
for (android.content.pm.Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
txt_key_fb.setText(something);
}
} 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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment