I use this code to generate my app keyhash:
public static String getKeyHash(Context context) {
String returner = "";
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.abc.mypackage", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
returner = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.e(TAG, Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e(TAG, e.toString());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Log.e(TAG, e.toString());
}
return returner;
}
The function is called from onCreate
function of Main Activity. And the generated hash is
ki4PhEa/cy/qsP/omrTEPkYFCDE=
Due to this Android app Key Hash doesn't match any stored key hashes, I replaced all the /
to _
and finally I get this
ki4PhEa_cy_qsP_omrTEPkYFCDE=
I put the keyhash to the Facebook developer site and save
When I login to Facebook, my app gives this exception (awesome !!!!)
02-26 23:05:49.008 4966-4966/? E/MyClassListViewAdapter﹕ Bad thing happened com.facebook.FacebookAuthorizationException: UnknownError: ApiException:Key hash ki4PhEa_cy_qsP_omrTEPkYFCDE does not match any stored key hashes.
How can I solve this ridiculous problem ?
Update This problem only occurs on my real device (Htc One X). It does not occur when running on emulator