android+linkedin+设计,Android - LinkedIn Integration

Android - LinkedIn Integration

Advertisements

Android allows your application to connect to Linkedin and share data or any kind of updates on Linkedin. This chapter is about integrating Linkedin into your application.

There are two ways through which you can integrate Linkedin and share something from your application. These ways are listed below.

Linkedin SDK (Scribe)

Intent Share

Integrating Linkedin SDK

This is the first way of connecting with Linkedin. You have to register your application and then receive some Application Id , and then you have to download the Linkedin SDK and add it to your project. The steps are listed below.

Registering your application

Create a new Linkedin application at https://www.linkedin.com/secure/developer. Click on add new application. It is shown below −

65116ee1d547c4b2e1b12b36330fd163.png

Now fill in your application name , description and your website url. It is shown below −

f0ee74e267bc2c536fea3148ed1b29ea.png

If everything works fine, you will receive an API key with the secret. Just copy the API key and save it somewhere. It is shown in the image below −

7069cea0ae6f2871449930591b749404.png

Downloading SDK and integrating it

Download Linkedin sdk here. Copy the scribe-1.3.0.jar jar into your project libs folder.

Posting updates on Linkedin application

Once everything is complete, you can run the Linkedin samples which can be found here.

Intent share

Intent share is used to share data between applications. In this strategy, we will not handle the SDK stuff, but let the Linkedin application handles it. We will simply call the Linkedin application and pass the data to share. This way, we can share something on Linkedin.

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, "Hello, from tutorialspoint");

startActivity(Intent.createChooser(shareIntent, "Share your thoughts"));

Apart from the these methods , there are other methods available that allows intent handling. They are listed below −

Sr.No

Method & description

1

addCategory(String category)

This method add a new category to the intent.

2

createChooser(Intent target, CharSequence title)

Convenience function for creating a ACTION_CHOOSER Intent

3

getAction()

This method retrieve the general action to be performed, such as ACTION_VIEW

4

getCategories()

This method return the set of all categories in the intent.nt and the current scaling event

5

putExtra(String name, int value)

This method add extended data to the intent.

6

toString()

This method returns a string containing a concise, human-readable description of this object

Example

Here is an example demonstrating the use of IntentShare to share data on Linkedin. It creates a basic application that allows you to share some text on Linkedin.

To experiment with this example, you can run this on an actual device or in an emulator.

Steps

Description

1

You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication.

2

Modify src/MainActivity.java file to add necessary code.

3

Modify the res/layout/activity_main to add respective XML components

4

Run the application and choose a running android device and install the application on it and verify the results

Following is the content of the modified main activity file MainActivity.java.

package com.example.sairamkrishna.myapplication;

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://comexample.sairamkrishna.myapplication/*");

try {

InputStream stream = getContentResolver().openInputStream(screenshotUri);

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

sharingIntent.setType("image/jpeg");

sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);

startActivity(Intent.createChooser(sharingIntent, "Share image using"));

}

});

}

}

Following is the modified content of the xml res/layout/activity_main.xml.

In the below code abc indicates the logo of tutorialspoint.com

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">

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" />

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" />

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"/>

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" />

Following is the content of AndroidManifest.xml file.

package="com.example.sairamkrishna.myapplication" >

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name=".MainActivity"

android:label="@string/app_name" >

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project's activity files and click Run

9930c18d4eba46df8c53351a9db3750a.png icon from the toolbar. Before starting your application, Android studio will display following window to select an option where you want to run your Android application.

ea5ea652f09dc083546688771d83a90c.png

Select your mobile device as an option and then check your mobile device which will display your default screen −

22f8f9626ca26d037e64ec6b77a9dbc2.png

Now just tap on the image logo and you will see a list of share providers.

540682a265e859d209757d86630377d4.png

Now just select Linkedin from that list and then write any message. It is shown in the image below −

5ef06f1f7e80ba24883b11f598c06ea2.png

Now it shows updating information

e1d86889d0a877d5154e2934f721661a.png

Advertisements

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值