Android-linkedin-integration

提供:Dev Guides
移動先:案内検索

Android-LinkedInの統合

Androidでは、アプリケーションをLinkedinに接続し、Linkedinでデータまたはあらゆる種類の更新を共有できます。 この章では、Linkedinをアプリケーションに統合する方法について説明します。

Linkedinを統合し、アプリケーションから何かを共有するには、2つの方法があります。 これらの方法を以下にリストします。

  • Linkedin SDK(Scribe)
  • インテントシェア

Linkedin SDKの統合

これは、Linkedinに接続する最初の方法です。 アプリケーションを登録してからApplication Idを受信し、Linkedin SDKをダウンロードしてプロジェクトに追加する必要があります。 手順は以下のとおりです。

アプリケーションを登録する

[[1]] [新しいアプリケーションの追加]をクリックします。 以下に示されています-

Android Linkedinチュートリアル

次に、アプリケーション名、説明、WebサイトのURLを入力します。 以下に示されています-

Android Linkedinチュートリアル

すべてが正常に機能する場合、シークレットを含むAPIキーを受け取ります。 APIキーをコピーして、どこかに保存するだけです。 それは以下の画像に示されています-

Android Linkedinチュートリアル

SDKをダウンロードして統合する

Linkedin sdk https://github.com/fernandezpablo85/scribe-java [こちら]をダウンロードします。 scribe-1.3.0.jar jarをプロジェクトのlibsフォルダーにコピーします。

Linkedinアプリケーションでの更新の投稿

すべてが完了したら、https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/LinkedInExample.java [こちらにある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 finddevguides");
startActivity(Intent.createChooser(shareIntent, "Share your thoughts"));

これらのメソッドとは別に、インテント処理を可能にする他のメソッドが利用可能です。 それらは以下にリストされています-

Sr.No Method & description
1

addCategory(String category)

このメソッドは、新しいカテゴリをインテントに追加します。

2

createChooser(Intent target, CharSequence title)

ACTION_CHOOSERインテントを作成するための便利な関数

3

getAction()

このメソッドは、実行される一般的なアクション(ACTION_VIEWなど)を取得します

4

getCategories()

このメソッドは、intent.ntのすべてのカテゴリのセットと現在のスケーリングイベントを返します

5

putExtra(String name, int value)

このメソッドは、拡張データをインテントに追加します。

6

toString()

このメソッドは、このオブジェクトの人間が読める簡潔な説明を含む文字列を返します

以下は、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 はfinddevguides.comのロゴを示します_

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

以下は AndroidManifest.xml ファイルの内容です。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.sairamkrishna.myapplication" >
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" >

      <activity
         android:name=".MainActivity"
         android:label="@string/app_name" >

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

      </activity>

   </application>
</manifest>

アプリケーションを実行してみましょう。 実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 Androidスタジオからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[画像を実行:/android/images/eclipse_run.jpg [Eclipse Run Icon]アイコンをクリックします。 アプリケーションを開始する前に、Androidスタジオは次のウィンドウを表示して、Androidアプリケーションを実行するオプションを選択します。

Android Linkedinチュートリアル

オプションとしてモバイルデバイスを選択し、デフォルト画面を表示するモバイルデバイスを確認します-

Android Linkedinチュートリアル

画像のロゴをタップするだけで、共有プロバイダーのリストが表示されます。

Android Linkedinチュートリアル

そのリストからLinkedinを選択して、メッセージを書きます。 それは以下の画像に示されています-

Android Linkedinチュートリアル

更新情報が表示されるようになりました

Android Twitterチュートリアル