Tuesday 14 April 2015

Generating KEY HASH programmactically for Signed android app

Put this code in your splash class or in Lanucher class before making the app signed.And after install the app and your signed key hash will be printed, which can be checked in logcat.

 
  try {

      PackageInfo info = getPackageManager().getPackageInfo("YOURPACKAGENAME", PackageManager.GET_SIGNATURES);

      for (Signature signature : info.signatures) {

      MessageDigest md = MessageDigest.getInstance("SHA");

      md.update(signature.toByteArray());

      String hashCode = Base64.encodeToString(md.digest(), Base64.DEFAULT);

      System.out.println("hashKey for Facebook :"+hashCode);

      Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));

      }

      } catch (NameNotFoundException e) {
  

      } catch (NoSuchAlgorithmException e) {

    
      }

      

No comments:

Post a Comment