0

I'm working on an Android application in which i have Facebook module.Everything was working fine until i exported the apk for uploading to Google Play.The app downloaded from Google Play failed to login to Facebook.Then i realized that it was the problem with my hash key since it was debug hash key.So i redid generating key.I followed this steps in the accepted answer Find the key hash for a signed app

But its not working yet.Somebody please help me...Thanks in advance...

Community
  • 1
  • 1
Nevaeh
  • 1,519
  • 7
  • 24
  • 45

1 Answers1

0

Hash key for debugging and release mode are different. Run your project in release mode with the following method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.hellofacebook", 
                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) {

    }

In logcat you will see new key hash. Copy and paste this Release Key Hash into your Facebook App ID's Android settings. Do not forget to change "com.facebook.samples.hellofacebook" with your package name.

ivkil
  • 414
  • 1
  • 4
  • 11
  • This way of generating key is for debug key na ?? – Nevaeh Jan 01 '15 at 09:00
  • It depends. If you are building a release version, you will obtain release Key Hash. If you are using Android Studio, check [this](https://developer.android.com/tools/building/building-studio.html) – ivkil Jan 01 '15 at 09:09
  • Actually, I do not know how to run release mode project in Eclipse. But you may: 1. Include this code to onCreate method of your MainActivity class. 2. Run project - obtain debug key hash (as I understand you have already it). 3. Rigth-click on project - go to Android Tools and choose Export Signed Application Package. 4. Install apk on mobile device and do not unplug usb cable from computer. 5. Launch app, see Log and compare hash keys. They will be different. I have tried this a few minutes ago. Suppose you may find better solution for this, but this one is working also. – ivkil Jan 01 '15 at 09:37