Blog

Latest technology news, trends and developers guide for business application. Visit this space for more tech updates.

Let’s work on your exciting new project together!

Step by Step Developers Guide to Integrate LinkedIn with an Android Application

Android App Development, Tech Blog, Tech Trends

LinkedIn is the most popular professional networking platform on which users can share updates about their professional lives including projects completed, milestones achieved and make new professional connections. It presents formal curriculum vitae of the individual which can be browsed by recruiters.

Overview of SDK

  • The mobile SDK for Android reduces your app’s time to market by providing out-of-box support for LinkedIn natively inside your Android applications.
  • The Mobile SDK for Android requires the official LinkedIn Android application is also installed to support the SDK’s capabilities.
  • The minimum supported version is Android 4.4.2 (API 19).

SDK Features

-Single sign-on (SSO) authentication, in conjunction with the LinkedIn mobile app.

-A convenient wrapper for making authenticated calls to LinkedIn’s REST APIs.

-“Deep linking” to additional member data in the LinkedIn mobile app.

-Sample application that demonstrates best-practice implementations of all of the SDK’s features.

Please find steps below for LinkedIn integration in Android.

Step 1- Create Application

-To Integrate LinkedIn in your mobile application, you need to create a new application using LinkedIn Developer’s Account

-Create application from LinkedIn developer account https://www.linkedin.com/developer/apps

Step 2- Set the Application Permission

You have to set the Default Application Permissions and to do that you have to select check box “r_basicprofile” and “r_emailaddress” and click on the “update” button to set the permission.

Step 3- Download Mobile LinkedIn SDK

Go to https://developer.linkedin.com/docs/android-sdk and download a Mobile SDK for Android

Step 4- Generate Hash Key

-Generate a hash key and integrate your app with LinkedIn account

-Go to https://www.linkedin.com/developer/apps

-Select your application name and click the Mobile tab

-Add the package name and generated hash key in your LinkedIn Application.

-This hash key will authenticate your mobile application.

Login

private static final String topCardUrl = "https://" + host + "/v1/people/~:(first-name,last-name,email-address,formatted-name,phone-numbers,public-profile-url,picture-url,picture-urls::(original))";
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS, Scope.W_SHARE);
}
public void loginLinkedin() {
LISessionManager.getInstance(getApplicationContext()).init(this,
buildScope(), new AuthListener() {
@Override
public void onAuthSuccess() {

APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest(MainActivity.this, topCardUrl, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse s) {

}

@Override
public void onApiError(LIApiError error) {
}
});

}

@Override
public void onAuthError(LIAuthError error) {

}
}, true);

Logout

LISessionManager.getInstance(getApplicationContext()).clearSession();
Check Login
private boolean isLogin(){
LISessionManager sessionManager = LISessionManager.getInstance(getApplicationContext());
LISession session = sessionManager.getSession();
boolean accessTokenValid = session.isValid();
return accessTokenValid;
}
Share Message
private static final String shareUrl = "https://" + host + "/v1/people/~/shares";

public void shareMessage() {
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.postRequest(MainActivity.this, shareUrl, buildShareMessage("Hello World", "Hello Title", "Hello Descriptions", "http://ankitthakkar90.blogspot.in/", "http://1.bp.blogspot.com/-qffW4zPyThI/VkCSLongZbI/AAAAAAAAC88/oGxWnHRwzBk/s320/10333099_1408666882743423_2079696723_n.png"), new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {

}

@Override
public void onApiError(LIApiError error) {

}
});
}
public String buildShareMessage(String comment,String title,String descriptions,String linkUrl,String imageUrl ){
String shareJsonText = "{ \n" +
" \"comment\":\"" + comment + "\"," +
" \"visibility\":{ " +
" \"code\":\"anyone\"" +
" }," +
" \"content\":{ " +
" \"title\":\""+title+"\"," +
" \"description\":\""+descriptions+"\"," +
" \"submitted-url\":\""+linkUrl+"\"," +
" \"submitted-image-url\":\""+imageUrl+"\"" +
" }" +
"}";
return shareJsonText;
}

Open Current User Profile

public void openUserProfile(){
DeepLinkHelper deepLinkHelper = DeepLinkHelper.getInstance();
deepLinkHelper.openCurrentProfile(MainActivity.this, new DeepLinkListener() {
@Override
public void onDeepLinkSuccess() {
}

@Override
public void onDeepLinkError(LIDeepLinkError error) {
}
});
}

Best Practices

Posting on member’s behalf :You should assure users that you will not post or send mail on their behalf without their consent, and give them the option to edit content before it is posted or not share content if they choose.

Permission Request:You should educate users on which permissions you are requesting and how this data will be used. LinkedIn does not support incremental permission request, so all permissions must be granted during the authorization step.

Authentication:

  • Remind the user that they are logged into your application by displaying their name, portrait, and/or account settings.
  • Avoid multiple log-in prompts
  • Cache the user’s access token after they grant your application and do not bring the user through the authentication flow again unless they log out or the access token expires or is otherwise invalid.
  • You should allow the user to log out, and when they do log out you should destroy the access token you had been granted.

Canceling in-progress requests: During your application’s workflow, you may wish to cancel any in-progress API requests. This is done by calling APIHelper.cancelCalls() method.

Using ProGaurd with your application: If you intend to use ProGuard on the release build of your mobile application, you will need to add the following lines to your project’s proguard-project.txt file to preserve information required for the SDK to function properly:

Proguard configuration- Keep class com.linkedin.** { *; } , keepattributes Signature

Mobile access tokens

It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.

Partnership Program

All other APIs (e.g. Connections, Groups, People Search, Invitation, Job Search, etc.) will require developers to become a member of one of our partnership programs.

Partnering with LinkedIn provides you with additional API functionality & data access, increased call limits & dedicated support.

Applications are only accepted when we feel that they’re providing value to members, developers, and LinkedIn.
https://developer.linkedin.com/partner-programs

References:

https://developer.linkedin.com/docs/android-sdk
https://developer.linkedin.com/docs/android-sdk-auth
https://developer.linkedin.com/downloads#androidsdk
https://www.numetriclabz.com/android-linkedin-integration-login-tutorial/
https://developer.linkedin.com/docs/oauth2
https://developer.linkedin.com/partner-programs/apply
https://developer.linkedin.com/support/developer-program-transition

You can Download source code of this example from Github.

5 Android App Development Success Mantras to Remember

It is common knowledge that launching the mobile application on Google Play Store will give...

How AI and ML Will Impact Mobile Application Development in Future

Smartphones become smarter than before. This is not just a word picture! Both Artificial Intelligence...

Get Your Apps Ready for Android O

The final developer preview of Android O, Google’s latest version of the mobile operating system...

Subscribe to our Newsletter Receive free e-guides, news, updates and more