语音技能快绑 UI 业务包

更新时间:2024-04-08 09:16:24下载pdf

涂鸦语音技能快速绑定 UI 业务包(简称技能快绑业务包)提供一键快速绑定 Amazon Alexa 和 Google Assistant 的自定义语音技能服务。

准备工作

集成业务包

在工程 Module 的 build.gradle 添加如下配置:


dependencies {
    api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
    implementation 'com.thingclips.smart:thingsmart-bizbundle-amazon_google_bind'
    implementation 'com.thingclips.smart:thingsmart-social_auth_manager'
    implementation 'com.thingclips.smart:thingsmart-social_auth_manager_ui'
    implementation 'com.thingclips.smart:thingsmart-aac-clean-kt'
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.72'
    implementation 'com.thingclips.smart:speech-skill-auth-manager:5.9.0'
    api "com.thingclips.smart:thingsmart:${sdk_version}}"
}

由于语音技能快速绑定 UI 业务包使用了 H5 商城内容,您需要添加 同版本的商城 H5 依赖。详情请参考 H5 商城 UI 业务包build.gradle 配置方式。您只需要引入依赖,不需要额外开通商城增值服务。

配置 app_scheme

  1. 在根目录 local.properties 配置 app_scheme 值,用于标识。此值取自于您基于 SDK 创建 App 时自定义的渠道标识符。

    app_scheme=testdemo
    
  2. 在工程 Module 的 build.gradle 里设置 AndroidManifest.xml 需要的参数:

    defaultConfig {
        ……
            Properties properties = new Properties()
            properties.load(project.rootProject.file('local.properties').newDataInputStream())
        manifestPlaceholders = [
                       INTERNAL_HOST: "${properties.getProperty("app_scheme")}".concat('.app.tuya.com'),
                    ALEXA_AUTH_INTERNAL_HOST: "${properties.getProperty("app_scheme")}".concat('.applink.smart321.com'),
                    ALEXA_AUTH_INTERNAL_HOST_NEW: "${properties.getProperty("app_scheme")}".toLowerCase(Locale.ENGLISH).concat('.applink.smart321.com'),
    
        ]
    }
    

配置 Amazon Alexa

res 资源文件中,添加如下配置:

// true 代表 Alexa 授权页面显示支持跳转客户自己 App 账号。false 代表 Alexa 授权页面显示不支持跳转客户自己 App 账号。
<bool name="is_show_alexa_oem_account"></bool>
// true 代表支持 Alexa 拉起 App 授权。false 代表不支持 Alexa 拉起 App 授权。
<bool name="is_alexa_to_thingpp_support">是否支持 Alexa 拉起 App 授权</bool>

配置 Google Assistant

res 资源文件中,添加如下配置:

<string name="google_flip_client_id">替换为涂鸦提供的 Client-ID</string>

您需要向涂鸦增值服务对接人员提供以下信息,涂鸦会根据这些信息为您提供 Google Action Client-ID:

  • 应用包名
  • 应用程序签名文件的 SHA256 密钥
  • 您在基于 SDK 创建 App 时自定义的渠道标识符,即 app_scheme 配置

绑定 Amazon Alexa 技能

接口说明

fun alexaBind(mActivity: Activity, homeId: String, callback: IThingResultCallback<Boolean>)

参数说明

参数 类型 说明
homeId String 家庭 ID
callback IThingResultCallback 回调结果

示例代码

ThingSocialLoginBindManager.Companion.getInstance().alexaBind(mActivity, homeId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {}

    @Override
    public void onError(String errorCode, String errorMessage) {}
});

绑定 Google Assistant 技能

接口说明

fun googleBind(mActivity: Activity, homeId: String, callback: IThingResultCallback<Boolean>)

参数说明

参数 类型 说明
homeId String 家庭 ID
callback IThingResultCallback 回调结果

示例代码

ThingSocialLoginBindManager.Companion.getInstance().googleBind(mActivity, homeId, new IThingResultCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {}

    @Override
    public void onError(String errorCode, String errorMessage) {}
});

解绑语音技能

实现 Amazon Alexa 和 Google Assistant 技能解绑功能,您只需获取解绑列表,处理列表单击事件。

获取技能绑定列表

接口说明

fun getAuthorityPlatforms(cb: ResultCallback<ArrayList<AuthorityBean?>>?)

AuthorityBean 数据模型

字段 类型 描述
time Number 授权时间
icon String 图标 URL
clientType String 平台
status Int
  • 1:授权
  • 0:没有授权
platformName String 平台名称,例如:
  • Alexa
  • Google

示例代码

SocialAuthManagerClient.INSTANCE.getInstance(MicroContext.getApplication())
            .getAuthorityPlatforms(new ResultCallback<ArrayList<AuthorityBean>>() {
                @Override
                public void onSuccess(ArrayList<AuthorityBean> authorityBeans) {
                    //get bound list success
                }

                @Override
                public void onFailure(@Nullable String s, @Nullable String s1) {
                    //get bound list onFailure
                }
            });

解绑技能

接口说明

//request code
private static final int REQUEST_REFRESH_MANAGER_AUTHORIZATION = 151;

// AuthorityBean to AuthPlatFormsBean
private void gotoDeAuthorize(Context context, AuthPlatFormsBean authPlatFormsBean) {
        UrlBuilder mBuilder = UrlRouter.makeBuilder(context, "SocialAuthManagerAppAction");
        Bundle newBundle = new Bundle();
        newBundle.putString("action", "gotoDeAuthorize");
        newBundle.putParcelable("authority_bean", authPlatFormsBean);
        mBuilder.setRequestCode(REQUEST_REFRESH_MANAGER_AUTHORIZATION);
        mBuilder.putExtras(newBundle);
        UrlRouter.execute(mBuilder);
    }

参数说明

参数 类型 说明
context Context Context
authPlatFormsBean AuthPlatFormsBean AuthPlatFormsBean 数据模型

更新技能绑定列表

回到调用页面更新解绑列表。

接口说明

   @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_REFRESH_MANAGER_AUTHORIZATION:
                if (RESULT_OK == resultCode) {
                  // 调用 getAuthorityPlatforms 方法,刷新技能列表。

                }
                break;
            default:
                break;
        }
    }
  • 建议使用 Release 版本调试技能快绑。

  • 智能生活 App SDK 会为您提供 Google Action Client-ID。同时,您需要自行提供以下信息:

    • 应用包名
    • SHA256 密钥
    • 您基于 SDK 创建 App 时自定义的渠道标识符,即 app_scheme 配置