Search code examples
javaandroidlinkedin-api

How to integrate login with Linked-in in android studio


i want to integrate login with linked in i have created app on linked developers account i have follow some tutorials but when i go to my app which i created i cant find Hash key and package name for android to connect this app to my application in android studio Can please someone tell me what should i do now Screenshot of Developer account of Tutorials i followed

This is my Developer Account Screen

Screenshot of My Developer account of linked-in

in Setting Tab i can only edit name description can someone tell how can i connect my app to linked app. i have already downloaded linked-in SDK and import it to my android studio Thanks in Advance


Solution

  • You can create hash key from below code

     fun getPackageHash() {
            try {
                @SuppressLint("PackageManagerGetSignatures")
                val info = context.packageManager.getPackageInfo(
                        "your package name",//give your package name here
                        PackageManager.GET_SIGNATURES)
                for (signature: Signature in info.signatures) {
                    val md = MessageDigest.getInstance("SHA")
                    md.update(signature.toByteArray())
    
                    Log.d("LinkedInSignInManager", "Hash  : " + Base64.encodeToString(md.digest(), Base64.NO_WRAP))//Key hash is printing in Log
                }
            } catch (e: PackageManager.NameNotFoundException) {
                Log.d("LinkedInSignInManager", e.message, e)
            } catch (e: NoSuchAlgorithmException) {
                Log.d("LinkedInSignInManager", e.message, e)
            }
        }
    

    you can get your package name from your app's build.gradle file in that applicationId is your package name.

    Add this both hash key and package name to link to your application