Guest User

Untitled

a guest
Dec 14th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /**
  2. * this method used to print out the hashkey of your application
  3. *
  4. * @param context
  5. * @return
  6. */
  7. public static String printKeyHash(Activity context) {
  8. PackageInfo packageInfo;
  9. String key = null;
  10. try {
  11. //getting application package name, as defined in manifest
  12. String packageName = context.getApplicationContext().getPackageName();
  13.  
  14. //Retriving package info
  15. packageInfo = context.getPackageManager().getPackageInfo(packageName,
  16. PackageManager.GET_SIGNATURES);
  17.  
  18. Log.e("Package Name=", context.getApplicationContext().getPackageName());
  19.  
  20. for (Signature signature : packageInfo.signatures) {
  21. MessageDigest md = MessageDigest.getInstance("SHA");
  22. md.update(signature.toByteArray());
  23. key = new String(Base64.encode(md.digest(), 0));
  24.  
  25. // String key = new String(Base64.encodeBytes(md.digest()));
  26. Log.e("Key Hash=", key);
  27. }
  28. } catch (PackageManager.NameNotFoundException e1) {
  29. Log.e("Name not found", e1.toString());
  30. } catch (NoSuchAlgorithmException e) {
  31. Log.e("No such an algorithm", e.toString());
  32. } catch (Exception e) {
  33. Log.e("Exception", e.toString());
  34. }
  35.  
  36. return key;
  37. }
Add Comment
Please, Sign In to add comment