To integrate LinkedIn with your mobile application, we need to create an new application in LinkedIn Developer’s Account. Go to https://www.linkedin.com/developer/apps and click on the Create Application button and a form will open that need to be filled to successfully create application on LinkedIn.
We need to set the permission to get the access to retrieve the user’s LinkedIn profile details. We need to select the r_basicprofile and r_emailaddress and click on the update button to set the permission. Download the Mobile LinkedIn SDK from https://developer.linkedin.com/downloads#androidsdk. Unzip the downloaded file and add the linkedin-sdk directory in your project. linkedin-sdk already exist in the unziped directory. Open setting.gradle file in your project and include linked-sdk directory in your project.include ':app', ':linkedin-sdk'
compile project(':linkedin-sdk')
compile 'com.squareup.picasso:picasso:2.5.2'
<TextView
android:id="@+id/hashKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"/>
//replace package string with your package string
public static final String PACKAGE = "Your Package";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
generateHashkey();
}
public void generateHashkey(){
try {
PackageInfo info = getPackageManager().getPackageInfo(
PACKAGE,
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
((TextView) findViewById(R.id.hashKey))
.setText(Base64.encodeToString(md.digest(),
Base64.NO_WRAP));
}
} catch (PackageManager.NameNotFoundException e) {
Log.d("Name not found", e.getMessage(), e);
} catch (NoSuchAlgorithmException e) {
Log.d("Error", e.getMessage(), e);
}
}
}