[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forumhttps://forums.developer.huawei.com...l/en/home?channelname=HuoDong59&ha_source=xda​

Introduction:

In this article, we will cover Integration of AGC App Linking in Unity Project using Official Plugin (Huawei HMS Core App Services).

Requirements:

1. Unity Editor

2. Huawei device

3. Visual Studio

Follows the steps.

Step 1. Create Unity Project.

Click unity icon.

Click NEW, select 3D, Project Name and Location.

Click CREATE, as follows.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909182613.96819752866054274486390465437934:50511013022117:2800:A4FE5D48A543A0316841C5CF1C648D6C3D62EDC5CB0D3A5364ED049DF4AA11C6.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909182613.96819752866054274486390465437934:50511013022117:2800:A4FE5D48A543A0316841C5CF1C648D6C3D62EDC5CB0D3A5364ED049DF4AA11C6.png[/IMG]

Step 2. Click Asset Store, search Huawei HMS Core App Services and click Import, as follows.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200930023653.45224303020233067845789826248723:50511013022117:2800:7D3F96A93125B32630A945320F289E6ADACBD196D0B35B79A39ED5B2FF365A28.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200930023653.45224303020233067845789826248723:50511013022117:2800:7D3F96A93125B32630A945320F289E6ADACBD196D0B35B79A39ED5B2FF365A28.png[/IMG]

Step 3. Once import is successful, verify directory in Assets > Huawei HMS Core App Services path, as follows.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909190648.33556446754008940797573999985728:50511013022117:2800:C25D8216B3D4DC583087DA824A567D7A269F9B5086D528D5572D7F66332B91D5.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909190648.33556446754008940797573999985728:50511013022117:2800:C25D8216B3D4DC583087DA824A567D7A269F9B5086D528D5572D7F66332B91D5.png[/IMG]

Step 4. Click Console and create a New Project.

Step 5. Choose Project Settings > Player and edit the required options in Publishing Settings, as follows.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909193633.77140517757452803046760722378315:50511013022117:2800:A43FCEDEB761783C9322376E82742936B121852C7A8EE12CF62A9D3460882C9F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909193633.77140517757452803046760722378315:50511013022117:2800:A43FCEDEB761783C9322376E82742936B121852C7A8EE12CF62A9D3460882C9F.png[/IMG]

Step 6. Verify the files created in Step 5.

Step 7. Download agconnect-services.json and copy to Assets>Plugins>Android, as follows.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909193849.52729613124561551678071615718070:50511013022117:2800:C0E8171B00C0CED9D1235EF8FE9DC69582822A1EA3BA72BE90EAD505CB4B412F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200909193849.52729613124561551678071615718070:50511013022117:2800:C0E8171B00C0CED9D1235EF8FE9DC69582822A1EA3BA72BE90EAD505CB4B412F.png[/IMG]

Step 8. Update the Package Name.

Step 9. Open LauncherTemplate.gradle and add below line

apply plugin: 'com.huawei.agconnect'

Step 10. Open "baseProjectTemplate.gradle" and add lines, as follows.

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

classpath 'com.huawei.agconnect:agcp:1.4.1.300'

Step 11. Open "mainTemplate.gradle" and add lines like shown below

apply plugin: 'com.huawei.agconnect'

implementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
implementation 'com.huawei.agconnect:agconnect-applinking:1.4.0.300'
implementation 'com.huawei.hms:hianalytics:5.0.3.300'

Step 12. Open AndroidManifest file and Add Activity like shown below.

<activity android:name="com.hms.hms_analytic_activity.TestAppLinksActivity"
android:theme="@style/UnityThemeSelector">

<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="developer.huawei.com" android:scheme="https" />
<data android:host="developer.huawei.com" android:scheme="http" />
</intent-filter>

</activity>

Step 13. Create TestAppLinksActivity.java, JavaCallBack.java and place it in Assets->Plugins->Android.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200922041629.16548004438754775938795657418579:50511013022117:2800:24CCDAF1BE0A59F337ACEB8AF68ABCFCD261455D5B23B0593D1ED6E6048DD5D0.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/002/032/901/2640091000002032901.20200922041629.16548004438754775938795657418579:50511013022117:2800:24CCDAF1BE0A59F337ACEB8AF68ABCFCD261455D5B23B0593D1ED6E6048DD5D0.png[/IMG]

//package com.test.applinks;
package com.hms.hms_analytic_activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import com.unity3d.player.UnityPlayerActivity;

import android.widget.Toast;
import com.huawei.agconnect.applinking.AGConnectAppLinking;
import com.huawei.agconnect.applinking.AppLinking;
import com.huawei.agconnect.applinking.ShortAppLinking;

//import androidx.appcompat.app.AppCompatActivity;

import com.huawei.agconnect.applinking.AGConnectAppLinking;

public class TestAppLinksActivity extends UnityPlayerActivity {

public static JavaCallback callback;

private static String agcLink = null;

private static final String DOMAIN_URI_PREFIX = "https://testulink.dra.agconnect.link";
//private static final String DEEP_LINK = "rmOb2";
private static final String DEEP_LINK = "https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides?id=123";

private static String deepLinkData = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Log.e("TestAppLinksActivity", "TestAppLinksActivity onCreate>> @@");

mContext = this.getApplicationContext();
handleAppLinking(getIntent());
}

public static void setCallback(JavaCallback callback1) {
Log.e("TestAppLinksActivityl", "setCallback>> @@");

callback = callback1;

if(callback != null){
Log.e("TestAppLinksActivity", "update c # script >>>>");
callback.OnJavaCallback(deepLinkData);

}else{
Log.e("TestAppLinksActivity", "TestAppLinksActivity callback is null plz initialize >>>>");
}
}

private void handleAppLinking(Intent intent) {
AGConnectAppLinking.getInstance().getAppLinking(this, intent).addOnSuccessListener(resolvedLinkData -> {
Uri deepLink = null;
if (resolvedLinkData != null) {
deepLink = resolvedLinkData.getDeepLink();
Log.e("TestAppLinksActivity", " getAppLinking@!!!$$->"+deepLink.toString());
deepLinkData = deepLink.toString();
if(callback != null){
Log.e("TestAppLinksActivity", "update c # script");
callback.OnJavaCallback(deepLink.toString());

}else{
Log.e("TestAppLinksActivity", "callback is null plz initialize");
}
}
}).addOnFailureListener(e -> {
Log.e("TestAppLinksActivity", "getAppLinking:onFailure", e);
});
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleAppLinking(intent);
}

public static void createAppLinking() {
AppLinking.Builder builder = new AppLinking.Builder().setUriPrefix(DOMAIN_URI_PREFIX)
.setDeepLink(Uri.parse(DEEP_LINK));
//longTextView.setText(builder.buildAppLinking().getUri().toString());
Log.e("TestAppLinksActivity", "createAppLinking long -->"+builder.buildAppLinking().getUri().toString());

agcLink = builder.buildAppLinking().getUri().toString();

builder.buildShortAppLinking(ShortAppLinking.LENGTH.SHORT).addOnSuccessListener(shortAppLinking -> {
//shortTextView.setText(shortAppLinking.getShortUrl().toString());
Log.e("TestAppLinksActivity", "createAppLinking short -->"+shortAppLinking.getShortUrl().toString());
agcLink = shortAppLinking.getShortUrl().toString();
}).addOnFailureListener(e -> {
//Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
Log.e("TestAppLinksActivity", "createAppLinking failure -->"+e.getMessage());
});
}

//public void shareLink() {
public static void shareLink(Activity activity){
if (agcLink != null) {
Log.e("TestAppLinksActivity", "shareLink agcLink is not null start activity");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, agcLink);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
//startActivity(intent);
}else{
Log.e("TestAppLinksActivity", " shareLink agcLink is null");
}
}

private static Context mContext;

public static Context getAppContext(){
return mContext;
}
}

code explanation : https://developer.huawei.com/consumer/en/codelab/AppLinking/index.html#7

package com.hms.hms_analytic_activity;

public interface JavaCallback {
void OnJavaCallback(String index);
}

Note : Java classes are using package name com.hms.hms_analytic_activity & we dont create any folder structure, this is allowed.

For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0202361288668900258&fid=0101188387844930001