Created
September 23, 2016 16:28
-
-
Save kevalpatel2106/4e8ff6c05f804b321566fbd0df875464 to your computer and use it in GitHub Desktop.
Get Hash key of the apk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Method is used to generate "Android Package Name" hash key | |
public void generateHashkey(){ | |
try { | |
PackageInfo info = getPackageManager().getPackageInfo( | |
com.android,//TODO: change to your package name. | |
PackageManager.GET_SIGNATURES); | |
for (Signature signature : info.signatures) { | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
((TextView) findViewById(R.id.package_name)).setText(info.packageName); | |
((TextView) findViewById(R.id.hash_key)).setText(Base64.encodeToString(md.digest(), | |
Base64.NO_WRAP)); | |
} | |
} catch (PackageManager.NameNotFoundException e) { | |
Log.d(TAG, e.getMessage(), e); | |
} catch (NoSuchAlgorithmException e) { | |
Log.d(TAG, e.getMessage(), e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment