Key hash for Facebook Android SDK

前端 未结 9 1931
后悔当初
后悔当初 2020-11-28 03:29

I can\'t figure out how to get the Key Hash required to use the Facebook Android SDK. I figured out that I can use keytool with these commands:

         


        
9条回答
  •  萌比男神i
    2020-11-28 04:02

    Best way is to generate Key-Hash using code:

     public static void generateKeyHash(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    "com.example.user2.testapp",
                    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) {
    
        } catch (NoSuchAlgorithmException e) {
    
        }
    }
    

    call this method once and generate key-hash, enjoy

提交回复
热议问题