Code2care : TechZone Apps & Tutorials

Generate facebook android SDK keyhash using java code

Trouble generating keyhash for facebook sdk integration with your application, here is the java code to generate keyhash.

Add the following code inside onCreate()

try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "YOUR_PACKAGE_NAME", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            System.out.println("KeyHash : "+ Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
Note : Do not forget to replace YOUR_PACKAGE_NAME with your Main activity package name.
After running the application you will find the keyhash in LogCat.






Popular tags
android
x 175
eclipse
x 29
notepadplusplus
x 20
macosx
x 14
sharepoint
x 14
html
x 14
mac
x 13
androidstudio
x 11




1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


Code2care © 2012-17