Android
How to Generate Key Hash for FaceBook Integration
To Generate Key Hash we have 2 Ways
Way 1 :
======
Just follow the below given Steps and you are done with this.
Step I: Download OpenSSL from here
Step II: Download openssl-0.9.8e_X64.zip for 64 bit PC and openssl-0.9.8e_WIN32.zip for 32 bit PC
Step III: once your download the zip folder. Go to C drive(where window is installed) and make a folder named OpenSSL
Step IV: extract all zip file in this folder.
Step V: Now go to Java folder and copy path of jre. For example: C:\Program Files\Java\jre1.8.0_101\bin
(make sure your are in JRE folder not in JDK folder,)
Step VI: Now open Cmd in your PC. Type Cd C:\Program Files\Java\jre1.8.0_101\bin
Now copy the below code after this
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Aravindraj\.android\debug.keystore" | "C:\openssl\bin\openssl" sha1 -binary |"C:\openssl\bin\openssl" base64
After this command will promt you for password. Just enter android .
You will have your key hash in front of you.
Way 2 : Generating keyHash Programatically
Inside oncreate Method of the Activity call this Function
printKeyHash(MainActivity.this);
Note:Replace Main activity with your activity name
public static String printKeyHash(Activity context) { PackageInfo packageInfo; String key = null; try { //getting application package name, as defined in manifest String packageName = context.getApplicationContext().getPackageName(); //Retriving package info packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); Log.e("Package Name=", context.getApplicationContext().getPackageName()); for (Signature signature : packageInfo.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); key = new String(Base64.encode(md.digest(), 0)); // String key = new String(Base64.encodeBytes(md.digest())); Log.e("Key Hash=", key); } } catch (PackageManager.NameNotFoundException e1) { Log.e("Name not found", e1.toString()); } catch (NoSuchAlgorithmException e) { Log.e("No such an algorithm", e.toString()); } catch (Exception e) { Log.e("Exception", e.toString()); } return key; }
Thanks, Happy Coding ;)
Comments
Post a Comment