Facebook Android Generate Key Hash

后端 未结 21 2039
误落风尘
误落风尘 2020-11-22 04:11

Trying to create an android app with Facebook integration, I\'ve gotten to the part in the docs where you have to generate a key hash file, it specifies to run the following

21条回答
  •  孤街浪徒
    2020-11-22 04:58

    At last :)

    Here my story :

    1. Add this code to your main activity, after you set layout.

      try { 
        PackageInfo info = getPackageManager().getPackageInfo("PROJECTNAME", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.e("MY KEY HASH:", sign);
            //textInstructionsOrLink = (TextView)findViewById(R.id.textstring);
            //textInstructionsOrLink.setText(sign);
            Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
        }
      } catch (NameNotFoundException e) {
          Log.d("nope","nope");
      } catch (NoSuchAlgorithmException e) {
      }
      
    2. Change PROJECTNAME to your package name!

    3. Sign your app (Android Tools->Export Signed Application)
    4. In your main activity where you paste code from 2 option, in your layout create TextView with id textstring
    5. uncomment two lines, that your sign code would be set to TextView 6 Wuolia, you have your HASH , install app on your phone!!! and check your hash Key!
    6. Now when it is visible , go to facebook app you created and add it to [Key Hashes]
    7. Note that your package name should be same as on facebook [Package Name] under [Key Hashes]
    8. Have a nice day :)

提交回复
热议问题