THIS CONTENT DOWNLOAD SHORTLY

Objective

The main objective of this post is to help you understand how to connect with Linkedin in Android.

 

You will get Final Output:

  • linkedin connectivity tutorial
  • android linkedin connectiviy demo
  • android linkedin connectiviy
  • android linkedin connection
 

Step 1 Create application from LinkedIn developer account.

Create application from your LinkedIn developer account. And copy paste ClientID and ClientSecrete to CONSUMER_KEY and CONSUMER_SECRET variable of Constant class.

If you don’t have developer account you can create your developer account from bellow link:

 

Step 2 Collect .jar files

First we need following .jar files:

  • commons-codec-1.3.jar
  • linkedin-j-android.jar
  • signpost-core-1.2.1.1.jar

Download it from the given link:

 

Step 3 Add .jar files

Add all three jar files to your Android Project to the following path ProjectName >> libs

 

Step 4 Constant.java file

Now Start Coding for the Linkedin API Create new class file named Constants.java

Put following code into class:

public class Constants 
{ 
public static final String CONSUMER_KEY = "xxxxxxxx"; // your KEY
public static final String CONSUMER_SECRET = "xxxxxxxx"; // your SECRET
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin";     
public static final String OAUTH_CALLBACK_HOST = "litestcalback";     
public static final String OAUTH_CALLBACK_URL =
OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
}
 

Step 5 MainActivity.java file

Then open your MainActivity.java file.

Put following details into your class:

private LinkedInOAuthService oAuthService;
private LinkedInApiClientFactory factory;
private LinkedInRequestToken liToken;
private LinkedInApiClient client;

Put following code into your onCreate() method:

if (android.os.Build.VERSION.SDK_INT > 9) {
   StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
         .permitAll().build();
   StrictMode.setThreadPolicy(policy);
}

Button btnLinkedinMain = (Button) findViewById(R.id.btnLinkedin);

btnLinkedinMain.setOnClickListener(this);
 

Step 6 onClick() method

Now Override onNewIntent() method into your Activity.

public void onClick(View v) 
{

   if (v.getId() == R.id.btnLinkedin) {

      oAuthService = LinkedInOAuthServiceFactory.getInstance()
            .createLinkedInOAuthService(Constants.CONSUMER_KEY,
                  Constants.CONSUMER_SECRET);
      System.out.println("oAuthService : " + oAuthService);

      factory = LinkedInApiClientFactory.newInstance(
            Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);

      liToken = oAuthService
            .getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
      
      Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken
            .getAuthorizationUrl()));
      startActivity(i);

   }
}
 

Step 7 onNewIntent() method

Now Override onNewIntent() method into your Activity.

try {
   linkedInImport(intent);
} catch (NullPointerException e) {
   e.printStackTrace();
}
 

Step 8 AndroidManifest.xml file

Open your AndroidManifest.xml file.

Add following Permission:

<activity 
android:name=".MainActivity"           
android:label="@string/title_activity_mainactivity"             
android:launchMode="singleInstance" >             

<intent-filter>                 
<action android:name="android.intent.action.MAIN" />               
<category android:name="android.intent.category.LAUNCHER" />             
</intent-filter>              

<intent-filter>                 
<action android:name="android.intent.action.VIEW" />               
<category android:name="android.intent.category.DEFAULT" />                 
<category android:name="android.intent.category.BROWSABLE" />                    
<data android:host="litestcalback"  // same as "OAUTH_CALLBACK_HOST" android:scheme="x-oauthflow-linkedin"/> 
// same as "OAUTH_CALLBACK_SCHEME"           
</intent-filter>       

</activity>

Note

When you got Network Provider Exception then put the following code into your Main Activity in onCreate() method

 

Step 9 StrictMode.ThreadPolicy

StrictMode.ThreadPolicy was introduced since API Level 9 and the default thread policy had been changed since API Level 11, which in short, does not allow network operation (include HttpClient and HttpUrlConnection) get executed on UI thread. if you do this, you get NetworkOnMainThreadException.

This restriction can be changed, using:

if (android.os.Build.VERSION.SDK_INT > 9) {StrictMode.ThreadPolicy policy = new 
StrictMode.ThreadPolicy.Builder().permitAll().build();StrictMode.setThreadPolicy(policy);}

Reference Links:

I hope you enjoy this tutorial and it would be helpful to you. you can download the Full Project from GitHub.

Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

An entrepreneur who has founded 2 flourishing software firms in 7 years, Tejas is keen to understand everything about gaming - from the business dynamics to awesome designs to gamer psychology. As the founder-CEO of a company that has released some very successful games, he knows a thing or two about gaming. He shares his knowledge through blogs and talks that he gets invited to.

face mask Belial The Demon Headgear Pocket Staff Magic