Skip to content

Instantly share code, notes, and snippets.

@mumer92
Last active March 21, 2017 06:25
Show Gist options
  • Save mumer92/6779e9ca160b4d4b643c to your computer and use it in GitHub Desktop.
Save mumer92/6779e9ca160b4d4b643c to your computer and use it in GitHub Desktop.
Generate Facebook KeyHash Android Programatically
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.loginhowto",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...other operations
}//end of onCreate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment