user4048334
user4048334

Reputation:

Get key hash for release

I have just release my android app and am getting key hash does not match error I have tried going through the terminal and got a key hash and put in the Facebook dev website but it still didn't work, now I am trying to log the key hash like is says to in the getting started guide and a bunch of SO question that I have been looking at for hours, but it seems the code is out of date, as I am getting an error for the .toByteArray(), and it doesn't work so any help on how to get this code to log my key hash or get it, would be great thanks. Heres my code

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 (PackageManager.NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

I have put this in my on create on my main activity.

Upvotes: 0

Views: 84

Answers (1)

Mark
Mark

Reputation: 1170

Make sure you import this

import android.content.pm.Signature;

and not this

import java.security.Signature;

Upvotes: 1

Related Questions