linkedin android,Android Linkedin集成

Android允许您的应用程序连接到Linkedin并在Linkedin上共享数据或任何类型的更新。本章是关于将Linkedin集成到您的应用程序中。

您可以通过两种方式集成Linkedin并从您的应用程序中共享内容。这些方法如下所列。

Linkedin SDK(Scribe)

Intent Share

整合Linkedin SDK

这是与Linkedin联系的第一种方式。您必须注册您的应用程序,然后接收一些应用程序ID,然后您必须下载Linkedin

SDK并将其添加到您的项目中。步骤如下。

注册您的申请

b84fc7aba14e39eabb4c1c4d390f5d0a.png

现在填写您的申请名称,说明和您的网站网址。如下所示 -

00afa50b143525c0ca19dfb8b1c1b807.png

如果一切正常,您将收到带有密码的API密钥。只需复制API密钥并将其保存在某处。如下图所示 -

74bb924bbe6eb48b031a8adb7add461a.png

下载SDK并集成它

在这里下载Linkedin sdk。将scribe-1.3.0.jar jar复制到项目libs文件夹中。

在Linkedin应用程序上发布更新

一切都完成后,您可以运行可在此处找到的Linkedin样本。

意图分享

意图共享用于在应用程序之间共享数据。在这个策略中,我们不会处理SDK的东西,但让Linkedin应用程序处理它。我们将简单地调用Linkedin应用程序并传递数据进行共享。这样,我们可以在Linkedin上分享一些东西。

Android提供意图库以在活动和应用程序之间共享数据。为了将其用作共享意图,我们必须为 ACTION_SEND 指定共享意图的类型。其语法如下 -

Intent shareIntent = new Intent();

shareIntent.setAction(Intent.ACTION_SEND);

接下来您需要定义要传递的数据类型,然后传递数据。其语法如下 -

shareIntent.setType("text/plain");

shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, from codingdict");

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

除了这些方法之外,还有其他可用的方法允许意图处理。它们列在下面 -

序号

方法和描述

1

addCategory(String category)

此方法向intent添加新类别。

2

createChooser(Intent target,CharSequence title)

用于创建ACTION_CHOOSER Intent的便捷功能

3

的getAction()

此方法检索要执行的常规操作,例如ACTION_VIEW

4

getCategories()

此方法返回intent.nt和当前缩放事件中所有类别的集合

5

putExtra(String name,int value)

此方法将扩展数据添加到intent。

6

toString()

此方法返回一个字符串,其中包含此对象的简洁,可读的描述

这是一个示例,演示如何使用IntentShare在Linkedin上共享数据。它创建了一个基本应用程序,允许您在Linkedin上共享一些文本。

要试验此示例,您可以在实际设备或模拟器中运行此示例。

序号

描述

1

您将使用Android studio在com.example.sairamkrishna.myapplication包下创建Android应用程序。

2

修改src / MainActivity.java文件以添加必要的代码。

3

修改res / layout / activity_main以添加相应的XML组件

4

运行应用程序并选择正在运行的Android设备并在其上安装应用程序并验证结果

以下是已修改的主活动文件 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"));

}

});

}

}

以下是xml res / layout / activity_main.xml 的修改内容。

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

以下是 AndroidManifest.xml 文件的内容。

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

让我们尝试运行您的应用程序。我假设您已将实际的Android移动设备与计算机相关联。要从Android工作室运行应用程序,请打开项目的某个活动文件,然后单击

eclipse_run.jpg工具栏中的“运行” 图标。在开始申请之前,Android

studio将显示以下窗口,以选择您要运行Android应用程序的选项。

561be470f1c9c22d9e459e7b8982feae.png

选择您的移动设备作为选项,然后检查您的移动设备,它将显示您的默认屏幕 -

32b7c751eb756ed6efac69ef25d7bbc5.png

现在只需点击图像徽标,您就会看到共享提供商列表。

26f95729eb0f42adafc485df29945278.png

现在只需从该列表中选择Linkedin,然后编写任何消息。如下图所示 -

7e3e42811980ea5d87a0f983d8f84f71.png

现在它显示更新信息

f74ec8e8ef97efc3ad214406539ba18d.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值