zoukankan      html  css  js  c++  java
  • Unity平台 | 快速集成华为AGC AppLinking服务

    快速集成华为AGC-AppLinking服务-unity平台

    我们应用需要使用跨平台的分享链接,刚好华为AppGallery Connect的AppLinking服务满足我们的使用场景。

    关于集成步骤,官网的资料写的有点多,我总结一下步骤:

    1. 创建应用,开通AppLinking服务并且创建链接签注。

    2. 在Unity项目里集成AppLinking SDK。

    3. 在Unity里导入HuaweiService的package。

    4. 创建AppLinking。

    5. 接收AppLinking链接并且测试。

    1、开通AppLinking服务& 创建链接前缀

    1、在AGC控制台,创建应用, 或者使用已有的应用),在界面上找到 我的项目 -> 增长–>AppLinking,点击立即开通

    在这里插入图片描述

    2、在刚刚开通的AppLinking下面,点击链接前缀页签,点击添加链接前缀,根据需要创建一个现网唯一的前缀。
    系统会自动帮你检测,保证你域名的全网唯一。

    在这里插入图片描述
    在这里插入图片描述

    2、在unity项目里面集成AppLinking SDK

    首先需要在unity项目里开通配置好安卓环境:
    1、 在Edit-Project Setting-Player-Publish Setting中启用Android的自定义清单和gradle

    在这里插入图片描述

    注意:进行此步操作前需要先在Unity Hub中安装Android编译依赖。如下图:

    在这里插入图片描述

    2、在AGC我的项目 -> 项目设置–> 常规 下面,下载agconnect-services.json文件到你的unity项目的Assets / Plugins / Android路径下。

    3、在Other Setting中配置包名:注意需要和AGC官网的包名保持一致:

    在这里插入图片描述

    4、配置项目级gradle,此处对应AssetsPluginsAndroid路径下的baseProjectTmeplate.gradle文件,添加如下内容

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

    5、配置应用级gradle,此处对应AssetsPluginsAndroid路径下的LauncherTmeplate.gradle文件,添加如下内容:

    dependencies {
        implementation 'com.huawei.agconnect:agconnect-applinking:1.4.1.300'
    }
    

    3、在Unity里导入HuaweiService的package;

    1、先将对应的package导入到工程里:可以直接在unity的window-asset-store中,直接搜索huawei,下载获取。或者可以直接使用此链接下载:

    2、下载完成后,在Unity中点击assets – Import package,然后,然后选择需要的包,点击Import即可

    在这里插入图片描述

    在这里插入图片描述

    4、创建AppLinking

    有两种方式创建AppLinking一种是直接在AGC界面上创建,另外一个是在unity项目里面用代码的API接口创建:下面就只介绍在Unity 项目中创建了。

    1、创建按钮

    点击GameObject- UI –Button创建两个按钮:按钮Text分别为create和share,点击按钮,然后在右侧选择 Add Component, 创建并且添加一个Script文件。

    在这里插入图片描述

    2、添加创建链接的方法:

    在testapp的Script文件中,并且添加如下方法:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using HuaweiService.AppLinking;
    using HuaweiService;
     
    public class testApp : MonoBehaviour
    {
        private const string URI_PREFIX = "https://testcocos1203.drcn.agconnect.link";
        private const string DEEP_LINK = "https://developer.huawei.com/consumer/cn/service/josp/agc/index.html";
     
    void Start()
        {
            
        }
     
        void Update()
        {
            
        }
     
    public void createLongLink() {
            AGConnectAppLinking.getInstance();
            AppLinking.Builder builder = createBuilder();
            Uri applinkingUri = builder.buildAppLinking().getUri();
            var link = applinkingUri.toString();
            Debug.Log ("AppLinking create" + link);
            GUIUtility.systemCopyBuffer = link;
        }
     
        public AppLinking.Builder createBuilder(){
            return AppLinking.newBuilder()
            .setUriPrefix(URI_PREFIX)
            .setDeepLink(Uri.parse(DEEP_LINK))
            .setAndroidLinkInfo(
                AppLinking.AndroidLinkInfo.newBuilder()
                .build());
        }
     
        public void OpenLink()
        {
            var activity = new Activity();
            var intent = new Intent();
            intent.setData(Uri.parse(GUIUtility.systemCopyBuffer));
            activity.startActivity(intent);
         }
    }
    

    3、方法与按钮绑定:

    回到Unity界面,点击按钮,然后在按钮右侧找到click,添加对应的控件:

    在这里插入图片描述

    在这里插入图片描述

    同样的方法,为share按钮也添加按钮方法。

    注意:可以将create按钮创建的.cs文件拖动到share按钮右侧面板的“add component”区域进行复用,添加click事件。

    5、接收相关AppLinking

    两个步骤,一个是配置过滤器,一个是配置getAppLinking方法。

    1、 配置manifest文件:注意这里是将DeepLink的域名的Scheme配置进去:

    例如我的DeepLink是 DEEP_LINK = 'https://developer.huawei.com/cn/';

    那么manifest文件就需要这样配置

    在这里插入图片描述

    6、打包测试,查看现象。

    1、应用运行以后,点击Create按钮,创建一个AppLinking链接, 然后点击share按钮,将按钮分享到浏览器。

    在这里插入图片描述

    2、 此时浏览器可以直接拉起应用,表示链接使用正常。

    在这里插入图片描述

    7、总结

    集成简单,SDK依赖体积小,可以实现跨平台的分享,Android和iOS都可以支持,不需要在不同的平台做不同的适配了,节约工作量。

    运营做推广可以再AGC界面上创建,开发做分享功能可以在端侧用代码创建,简直完美。

    参考文档:

    华为AGC AppLinking服务开发文档:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-applinking-introduction

    Unity的AppLinking服务开发文档: https://docs.unity.cn/cn/Packages-cn/com.unity.hms@1.3/manual/applinking.html#integrating-huawei-analytics-kit

    Unity Editor安装和Apk打包:https://developer.huawei.com/consumer/cn/forum/topic/0204405811539110247?fid=18


    原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0201428957991340017?fid=0101271690375130218

    原作者:Mayism

  • 相关阅读:
    FirstApp,iphone开发学习总结10,归档(序列化、固化)
    FirstApp,iphone开发学习总结9,旋转
    iphone开发学习,开源之UIAlertViewBlocks
    FirstApp,iphone开发学习总结13,方向感应和通告
    iphone开发学习,开源之Three20
    FirstApp,iphone开发学习总结11,表操作(移动、删除)
    FirstApp,iphone开发学习总结12,播放音乐、视频
    iphone开发学习,开源,ASIHTTPRequest的学习
    iphone开发学习,开源之SVWebViewController,UIWebView支持后退、前进、刷新、使用Safari打开
    iphone开发学习,Block
  • 原文地址:https://www.cnblogs.com/developer-huawei/p/14297969.html
Copyright © 2011-2022 走看看