Skip to content

Instantly share code, notes, and snippets.

@Isabellle
Created April 7, 2016 18:45
Show Gist options
  • Save Isabellle/1113a4b409ef55c7b9000573751d5977 to your computer and use it in GitHub Desktop.
Save Isabellle/1113a4b409ef55c7b9000573751d5977 to your computer and use it in GitHub Desktop.
Display HashKey in Java
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.yourpackagename", PackageManager.GET_SIGNATURES); //Your package name here
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment