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 key hash in LogCat.

Generate Facebook Android SDK key hash using java code
Generate Facebook Android SDK key hash using java code
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency