简体   繁体   中英

Hash key release in Android for Facebook

I am trying to get the hash for the realese application with this code on the Splash class

try {
    PackageInfo info = getPackageManager().getPackageInfo("com.myapp", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
} catch (PackageManager.NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {

}

The problem is that getPackageManager().getPackageInfo("com.myapp", PackageManager.GET_SIGNATURES) throws an error that can't find the package.

The package name is the same that is in the AndroidManifest.xml

Thank you

The problem was that the package name I should use is the one defined in build.gradle and not in the AndroidManifest.xml.

I am using Gradle with different flavours, so I used the applicationId for the flavour that is for production.

I hope this is useful for someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM