📜  Android-LinkedIn集成

📅  最后修改于: 2021-01-05 05:19:52             🧑  作者: Mango


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

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

  • Linkedin SDK(抄写员)

  • 意向分享

集成Linkedin SDK

这是与Linkedin联系的第一种方式。您必须注册您的应用程序,然后接收一些应用程序ID,然后您必须下载Linkedin SDK并将其添加到您的项目中。步骤在下面列出。

注册您的申请

https://www.linkedin.com/secure/developer上创建一个新的Linkedin应用程序。单击添加新应用程序。它显示如下-

Android Linkedin教程

现在填写您的应用程序名称,描述和您的网站网址。它显示如下-

Android Linkedin教程

如果一切正常,您将收到包含密钥的API密钥。只需复制API密钥并将其保存在某处即可。如下面的图片所示-

Android Linkedin教程

下载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 tutorialspoint");
startActivity(Intent.createChooser(shareIntent, "Share your thoughts"));

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

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

这是一个演示使用IntentShare在Linkedin上共享数据的示例。它创建一个基本的应用程序,使您可以在Linkedin上共享一些文本。

要试验该示例,您可以在实际设备或仿真器上运行它。

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

以下是修改后的主要活动文件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的修改内容。

在下面的代码中abc表示tutorialspoint.com的徽标



   
   
      
   
      
   
      
   
      

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



   
      
      
         
         
            
            
         
         
      
      
   

让我们尝试运行您的应用程序。我假设您已将实际的Android Mobile设备与计算机连接。要从Android Studio运行该应用,请打开您项目的活动文件之一,然后点击运行Eclipse运行图标工具栏中的图标。在启动应用程序之前,Android Studio将显示以下窗口,以选择要在其中运行Android应用程序的选项。

Android Linkedin教程

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

Android Linkedin教程

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

Android Linkedin教程

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

Android Linkedin教程

现在显示更新信息

Android Twitter教程