HuaweiAGCをすばやく統合-AppLinkingサービス-Androidプラットフォーム

最近、私のアプリケーションはクロスプラットフォーム共有リンクを使用する必要があります。HuaweiAppGalleryConnectのAppLinkingサービスが私の使用シナリオを満たしているのはたまたまです。

統合手順については、公式サイトに多くの情報があります
。手順をまとめます。i。手順1:アプリケーションを作成してAppLinkingサービスを有効化する

ii。ステップ2:リンクプレフィックスを作成する

iii。ステップ3:AppLinkingSDKをAndroidプロジェクトに統合します。

iv。ステップ4:AppLinkingを作成する

v。ステップ5:AppLinkingリンクを受信して​​テストします。

1.アプリケーションを作成し、AppLinkingサービスをアクティブ化します

AGCコンソールアプリケーションを作成したり、既存のアプリケーションを使用して、マイプロジェクトを見つける- >成長- >インターフェイス上AppLinking、およびアクティベート今すぐ]をクリックします。

ここに写真の説明を挿入

開いた後、必ず[マイプロジェクト]-> [プロジェクト設定]-> [一般]に移動し、agconnect-services.jsonファイルをAndroidプロジェクトのアプリパスにダウンロードしてください。

ここに写真の説明を挿入

2.リンクプレフィックスを作成します

アクティブ化されたばかりのAppLinkingで、[リンクプレフィックス]タブをクリックし、[リンクプレフィックスの追加]をクリックして、必要に応じてライブネットワーク上に一意のプレフィックスを作成します。

システムは自動的にユーザーをチェックして、ドメイン名がネットワーク全体で一意であることを確認します。

ここに写真の説明を挿入

ここに写真の説明を挿入

3. AppLinkingSDKをAndroidプロジェクトに統合します

SDKアドレスを構成し、Androidプロジェクトを開き、プロジェクトレベルのbuild.gradleファイルで以下を構成します。

buildscript {
repositories {
//….
        maven {url 'https://developer.huawei.com/repo/'}
    }
    dependencies {
        //….
        classpath 'com.huawei.agconnect:agcp:1.4.1.300'![在这里插入图片描述](https://img-blog.csdnimg.cn/20201229190623817.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDcwODI0MA==,size_16,color_FFFFFF,t_70#pic_center)

    }
}

allprojects {
    repositories {
//….
        maven {url 'https://developer.huawei.com/repo/'}
    }
}

アプリケーションレベルのbuild.gradleファイルを開き、AppLinkingとHuawei Analytics SDKを構成し、以下の赤でマークされたコンテンツを構成します。

…
apply plugin: 'com.huawei.agconnect'
 ...
dependencies {
 ...
implementation "com.huawei.agconnect:agconnect-applinking:1.4    
implementation 'com.huawei.hms:hianalytics:5.0.4.301'.1.300"
}

4.AppLinkingを作成します

AppLinkingを作成する方法は2つあります。1つはAGCインターフェイスで直接作成する方法、もう1つはコードのAPIインターフェイスを使用してAndroidプロジェクトで作成する方法です。

4.1AGCインターフェイスでAppLinkingを作成します。

1.インターフェイスエントリは次のとおりです。[AppLinkingの作成]をクリックし、手順に従ってステップバイステップで作成します。

ここに写真の説明を挿入

2.デフォルトのディープリンク構成で、Huaweiの公式ウェブサイトを思いのままに見つけました。Androidのディープリンクの構成に注意してください。

ここに写真の説明を挿入

3.次のように構成されたAndroidリンクの動作:Androidアプリケーションで開きます。

ここに写真の説明を挿入

作成後、コピーしてご利用いただけます

ここに写真の説明を挿入

4.2エンドサイドコードの作成AppLinking

1.最初にactivity_main.xmlでインターフェイスを構成します。1つは作成用、もう1つは共有用の2つのボタンです。次に、AppLinkingを表示するTextView表示ボックスを作成します。

<Button
        android:id="@+id/create"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Create App Linking"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.4" />

    <TextView
        android:id="@+id/showLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="your App Linking"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.5" />

    <Button
        android:id="@+id/shareLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Share App Linking"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.8" />

以下に示すように:

ここに写真の説明を挿入

2.次に、作成したばかりのリンクプレフィックスをコピーして定数に追加し、最初に開く必要のあるDeepLinkアドレスを構成します。

private static final String DOMAIN_URI_PREFIX = "https://testapplinking1016.drcn.agconnect.link";
 private static final String DEEP_LINK = " https://consumer.huawei.com/cn/";
private static final String Android_DEEP_LINK = "myapp://testapplinking/?data=1016";
 private String shortLink;

ここに写真の説明を挿入

2. MainActivityのOnCreateで、作成ボタンを使用してAppLinkingを作成します

findViewById(R.id.create).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
                 AppLinking.Builder builder = new AppLinking.Builder()
                         .setUriPrefix(DOMAIN_URI_PREFIX)
                         .setDeepLink(Uri.parse(DEEP_LINK))
                         .setAndroidLinkInfo(new AppLinking.AndroidLinkInfo.Builder()
.setAndroidDeepLink(Android_DEEP_LINK).build());.build());

                 builder.buildShortAppLinking().addOnSuccessListener(shortAppLinking -> {
                         shortLink = shortAppLinking.getShortUrl().toString();
                         TextView showAppLinking = findViewById(R.id.showLink);
                         showAppLinking.setText(shortLink);
                 }).addOnFailureListener(e -> {
                         Log.e("AppLinking", "Failure + "+ e.getMessage());
                 });
    }
});

3. shareLinkボタンを使用して、作成したばかりのAppLinkingを共有します

findViewById(R.id.shareLink).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, shortLink);
        startActivity(intent);
    }
});

ここに写真の説明を挿入

5.関連するAppLinkingを受信します

受信するときは2つのステップがあります。1つはマニフェストファイルを構成すること、もう1つはリンクエントリでgetAppLinkingメソッドを構成することです。1
。マニフェストファイルを構成する:これはDeepLinkドメイン名のスキームを構成することに注意してください。たとえば
、私のDeepLinkは次のとおりです。 DEEP_LINK = "myapp:// testapplinking /?data = 1016";
private static final String DEEP_LINK = "myapp:// testapplinking /?data = 1016";

次に、マニフェストファイルを次のように構成する必要があります

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="testapplinking" android:scheme="myapp" />
</intent-filter>

ここに写真の説明を挿入

2. OnCreateの正面玄関で、getAppLinkingを構成し、リンクを取得して表示します

AGConnectAppLinking.getInstance().getAppLinking(this).addOnSuccessListener(resolvedLinkData -> {
        if (resolvedLinkData != null) {
                 String Result = resolvedLinkData.getDeepLink().toString();
                 TextView showAppLinking = findViewById(R.id.showLink);
                 showAppLinking.setText(Result);
        }
});

ここに写真の説明を挿入

6.パックテストを行い、現象を確認します。

1.アプリケーションの実行後、[作成]ボタンをクリックしてAppLinkingリンクを作成し、インターフェイスに表示します。

ここに写真の説明を挿入

ここに写真の説明を挿入

2. [共有]ボタンをクリックして、メモ内のAppLinkingリンクを共有し、一時的に保存します。次に、メモ内のリンクをクリックして、ブラウザーから開きます。ブラウザでアプリケーションを直接開くことができ、テストが完了します。

(インターフェースから作成されたAppLinkingも同じです。最初に付箋にコピーしてから、クリックして付箋をテストできます)

詳細については、以下を参照してください。

  https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-applinking-introduction

ここに写真の説明を挿入

ここに写真の説明を挿入

ここに写真の説明を挿入

7.まとめ

統合は簡単で、SDKは小さなサイズに依存し、クロスプラットフォーム共有を実現できます。AndroidとiOSの両方でサポートできます。プラットフォームごとに異なる調整を行う必要がないため、ワークロードを節約できます。

操作とプロモーションはAGCインターフェースで作成でき、開発と共有機能はエンド側のコードで作成できます。これは完璧です。

参照文書:

Huawei AGC AppLinkingサービス開発ドキュメント:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-applinking-introduction


元のリンク:https://developer.huawei.com/consumer/cn/forum/topic/0204406653695530273?fid=0101271690375130218

著者:Jessyyyyy

おすすめ

転載: blog.51cto.com/14772288/2577286
おすすめ