Saturday, April 28, 2018

Android - Hash Key of Application

Introduction: Register an Android application for a 3rd party like Facebook. We always need Hash key of APK. Here, i'm going to explain a simple code snippet that gets hash key of your debug and release Apk.

So, First of all, if you want Hash key of debugging apk just paste the following code snippet anywhere in your Java/Kotlin class.


public void generateKeyHash() {
     try {
            PackageInfo info = getPackageManager().getPackageInfo( getPackageName(),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 (PackageManager.NameNotFoundException e) {
           Log.i("","");
         } catch (NoSuchAlgorithmException e) {
            Log.i("","");
         }
}
Now press ALT+6, You will see hash key in the log.






Now, If you want hash key of release Apk. You can do it with simple two steps.

1. The first step is the same as above.

2. Now generate release Apk. Install it in the device and connect it with android studio and press ALT+6. You will see Hash key as above. After that, you can delete code snippet and generate another singed build.
Share:

0 comments:

Post a Comment

We're Social

Categories

Ad here

  • Cover art Blend

    Blend app is very advanced app there are lots of features like shayari, status, chat, feed....