I\'m working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the readme.md (text file) in there,
Simply Open you Main Activity File and create below mention function:
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your.application.package.name",
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) {
}
1.1 Run you Application, this will generate a Hash key for your application.
Now, Open log cat and search with "KeyHash" and copy the hash key.
One you generate the Hash key you can remove this function.
I did a small mistake that should be kept in mind. If you are using your keystore then give your alias name, not androiddebugkey...
I solved my problem. Now if Facebook is there installed in my device, then still my app is getting data on the Facebook login integration. Just only care about your hash key.
Please see below.
C:\Program Files\Java\jdk1.6.0_45\bin>keytool -exportcert -alias here your alias name -keystore "G:\yourkeystorename.keystore" |"G:\ssl\bin\openssl" sha1 -binary | "G:\ssl\bin\openssl" base64
Then press Enter - it will ask you for the password and then enter your keystore password, not Android.
Cool.
You need to create a keystore by the keytool for signed apps for android like the procedure described in Android Site and then you have to install cygwin and then you need to install openssl from google code then just execute the following command and you will get the hash key for android and then put that hash key into the facebook application you created. And then you can access the facebook application through the Android Application for posting wall ("publish_stream") could be an example.
$ keytool -exportcert -alias alias_name -keystore sample_keystore.keystore | openssl sha1 -binary | openssl base64
You need to execute the above command from cygwin.
For an Android application
This code is used to get the hash key in your Android application for Facebook integration. I have tested all devices and it's working. Only change the package name of this code:
private void facebookHashKey() {
try {
PackageInfo info = getPackageManager().getPackageInfo("com.app.helpcove", 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("Print the hashKey for Facebook :"+hashCode);
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
Add this code to onCreate
of your activity, it will print the hash under the KeyHash tag in your logCat
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(),
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 (NameNotFoundException e) {
}
catch (NoSuchAlgorithmException e) {
}
You can add multiple hashkeys for your account, so if you been running in debug don't forget to run this again in release mode.
download openSSL for windows in here you can find 64bit and 32bit here
extract the downloaded file
C:\Users\username\.android\debug.keystore
keytool -exportcert -alias androiddebugkey -keystore C:\Users\username.android\debug.keystore | "C:\openSSL\bin\openssl" sha1 -binary | "C:\openSSL\bin\openssl" base64