Search code examples
androidandroid-emulatorandroid-facebookandroid-debug

Android Facebook Integration Invalid Key hash error on Android device but working fine on Emulator


When I run my Android app in my android device it was working fine when I clicked first time on Continues with Facebook button.When i try to login again after logged out it is showing an error "Invalid Key has" The key has does not match any stored key hash. I have already regenerated key hash and replaced new key on facebook. bUt still did not get result.

First time I had easily logged-in, But after logged out again I'm trying to Continues with Facebook but it is showing an error message "Invalid Key has":

But the same application is running perfectly fine on Emulator. why it is not working on my devices?


Solution

  • Hi Put this code in any reachable activity's onCreate method to print the hash key in the console and update that hash key in your facebook linked account with the application.

    try {
                PackageInfo info = getPackageManager().getPackageInfo(
                        "com.facebook.samples.loginhowto", 
                        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) {
    
            }