Android LinkedIn Integration: Android - LeaVe my baThRoom at-least !

LinkedIn is a business and employment-oriented social networking service that operates via websites and mobile apps. It is mainly used for professional networking, including employers posting jobs and job seekers posting their curriculum vitae. LinkedIn allows members (both workers and employers) to create profiles and "connections" to each other in an online social network which may represent real-world professional relationships. It presents curriculum vitae of the individual which can be browsed by recruiters.
Android LinkedIn Integration
Android allow applications to connect to LinkedIn and share data or any kind of updates on LinkedIn.
Following are the ways through which you can integrate LinkedIn in application
  • LinkedIn SDK(Scribe)
  • Intent Share
1. LinkedIn SDK(Scribe)

The mobile SDK for Android increases your app's time to market by providing out-of-box support for LinkedIn natively inside your Android applications. This allows you to boost your sign in conversion rates and provides you more time to work on the things that matter.

The SDK provides:
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.

Follow steps to integrate LinkedIn SDK 

Creating a new app in LinkedIn Developer account
Create a new LinkedIn application at https://www.linkedin.com/developer/apps. Click on Create new Application and follow the setup.
 create LinkedIn developer app
Fill following form
 create LinkedIn developer app form

 you will get Application ID for your Application

Create new Android Project
Open AndroidManifest.xml file and include the following code given below:
<uses-permission android:name="android.permission.INTERNET" />

Download Mobile LinkedIn SDK 
Go to https://developer.linkedin.com/docs/android-sdk  and download a Mobile SDK for Android.
Unzip the file and add LinkedIn-sdk folder in your project.

Add Mobile LinkedIn SDK in project
Open setting.gradle file in your project and include linkedin-sdk folder in your project.
include ':app',':linkedin-sdk

Adding library in depencencies
Add the following code in the file’s (/app/build.gradle file) dependencies to compile linkedin-sdk
compile project(':linkedin-sdk')
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.hdodenhof:circleimageview:1.3.0'

Synchronize your project
Generate hash Key
We need to generate a hash key. This generated Hash key will integrate your app with LinkedIn account.

Adding hash key in your LinkedIn Developer 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.
LinkedIn developer app hash key

Once everything is complete, you can run the Linkedin sample application

2. Intent Share

An android share intent allow your app to share contents such as URL or text and Image to other apps installed in your Android device like Facebook, Twitter, Messaging, Instagram, whatsapp, etc.
 Android provides intent library to share data between activities and applications. In order to use it as share intent , we have to specify the type of the share intent to ACTION_SEND. Its syntax is given below
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Next thing you need to is to define the type of data to pass , and then pass the data. Its syntax is given below 
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, " From Suven Consultency");
startActivity(Intent.createChooser(shareIntent, "Hello!!!!"));
Example
here is an example to share data on Linkedin using intent share.
  • You will use Android studio to create an Android application under a package net.suven.android.android_linkedinintegration.
  • Modify src/MainActivity.java file to add necessary code.
  • Modify the res/layout/activity_main to add respective XML components.
  • Run the application and choose a running android device and install the application on it and verify the results.
MainActivity.java
package net.suven.android.android_linkedinintegration;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class MainActivity extends AppCompatActivity {
   private ImageView img;

   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      img = (ImageView) findViewById(R.id.imageView);
      Button b1 = (Button) findViewById(R.id.button);

      b1.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            Uri screenshotUri = Uri.parse("android.
               resource://net.suven.android.android_linkedinintegration/*");

            try {
               InputStream stream = getContentResolver().openInputStream(screenshotUri);
            } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }

            sharingIntent.setType("suvenlogo/jpeg");
            sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
            startActivity(Intent.createChooser(sharingIntent, "Share image using"));
         }
      });
   }
}
activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools" 
   android:layout_width="match_parent"
   android:layout_height="match_parent" 
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" 
   tools:context=".MainActivity">
   
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:textSize="30dp"
      android:text="Linkedin Share" />
      
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Tutorials Point"
      android:id="@+id/textView2"
      android:layout_below="@+id/textView"
      android:layout_centerHorizontal="true"
      android:textSize="35dp"
      android:textColor="#ff16ff01" />
      
   <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView"
      android:layout_below="@+id/textView2"
      android:layout_centerHorizontal="true"
      android:src="@drawable/logo"/>
      
   <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Share"
      android:id="@+id/button"
      android:layout_marginTop="61dp"
      android:layout_below="@+id/imageView"
      android:layout_centerHorizontal="true" />
      
</RelativeLayout>
Following is the output of application.

android linkedin integration app

Click on share button. you will see list of share provider
share post

Now select LinkedIn from the list and then write your message shown in following image 
write linkedin post

Comments

Popular posts from this blog

How E-commerce Sites can Increase Sales with Pinterest?

Every thing U can do with a Link-List + Programming_it_in_JaVa

Test Your SQL Basics - Part_1