SDK基础包

更新时间:2020-02-10 11:19:04

基础包主要包含API通道,BoneMobile容器库。

API通道

概述

API 通道 SDK 是 IoT 官方服务的 API 通道。 API 通道 基于 HTTP 协议,并通过整合安全组件来提升通道的安全性

初始化

参考下载通过平台下载包里面的说明

如何使用

发送请求请参考如下代码:

// 构建请求
        IoTRequest request = new IoTRequestBuilder()
                .setScheme(scheme) // 如果是HTTPS,可以省略本设置
                .setHost(host) // 如果是IoT官方服务,可以省略本设置
                .setPath("/kit/debug/ping") // 参考业务API文档,设置path
                .setApiVersion("1.0.0")  // 参考业务API文档,设置apiVersion
                .addParam("input", "测试") // 参考业务API文档,设置params,也可使用setParams(Map<Strign,Object> params)
                .build();
        // 获取Client实例,并发送请求
        IoTAPIClient ioTAPIClient = new IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, new IoTCallback() {
            @Override
            public void onFailure(IoTRequest request, Exception e) {
                // 根据 e, 处理异常
            }
            @Override
            public void onResponse(IoTRequest request, IoTResponse response) {
                int code = response.getCode();
                // 200 代表成功
                if(200 != code){
                    String mesage = response.getMesasge();
                    String localizedMsg = response.getLocalizedMsg();
                    // 根据 mesage 和 localizedMsg,处理失败信息
                    ...
                    return;
                }
                Object data = response.getData();
                // 解析 data
                ...
            }
        });

混淆配置


-keep public class com.aliyun.iot.aep.sdk.apiclient.** {
    public <methods>;
    public <fields>;
}

长连接通道

概述

长连接通道SDK,提供 IoT 业务协议封装的云端数据下行能力;为 app 提供订阅、发布消息的能力, 和支持请求响应模型。

初始化

参考通过平台下载包里面的说明。

如何使用

SDK 封装了上行 RPC 请求、订阅、取消订阅等接口,详细接口可以参考 IMobileChannel

业务请求响应模型

业务请求响应模型示例:

//带请求响应的 RPC 请求
String topic = "path/of/topic";
JSONObject params = new JSONObject();
params.put("key","value");
MobileChannel.getInstance().asyncSendRequest(topic, null, params, new IMobileRequestListener() {
    @Override
    public void onSuccess(String jsonData) {
        ALog.d(TAG,"onSuccess, rsp = "+jsonData);
    }
    @Override
    public void onFailure(AError error) {
        ALog.d(TAG,"onFailure");
    }
});

订阅 Topic

//订阅请求
String topic = "path/of/topic";
MobileChannel.getInstance().subscrbie(topic, new IMobileSubscrbieListener() {
    @Override
    public void onSuccess(String topic) {
        ALog.d(TAG,"onSuccess, topic = "+topic);
    }
    @Override
    public void onFailed(String topic, AError error) {
        ALog.d(TAG,"onFailed, topic = "+topic);
    }
    @Override
    public boolean needUISafety() {
        return false;
    }
});

取消订阅 Topic

//取消订阅
String topic = "path/of/topic";
MobileChannel.getInstance().unSubscrbie(topic, new IMobileSubscrbieListener() {
    @Override
    public void onSuccess(String topic) {
        ALog.d(TAG,"onSuccess, topic = "+topic);
    }
    @Override
    public void onFailed(String topic, AError error) {
        ALog.d(TAG,"onFailed, topic = "+topic);
    }
    @Override
    public boolean needUISafety() {
        return false;
    }
});

Publish 数据

//Publish 请求
String topic = "path/of/topic";
JSONObject params = new JSONObject();
params.put("key","value");
MobileChannel.getInstance().ayncSendPublishRequest(topic, params, new IMobileRequestListener() {
    @Override
    public void onSuccess(String jsonData) {
        ALog.d(TAG,"onSuccess, rsp = "+jsonData);
    }
    @Override
    public void onFailure(AError error) {
        ALog.d(TAG,"onFailure");
    }
});

注册下行 Listener

设置长连接通道连接变化以及云端推送的下行消息监听事件。详细接口可以参考 IMobileChannel

/**

* 设置通道的下推回调,如果不需要用的时候,记得调用 unRegisterDownstreamListener

*/
MobileChannel.getInstance().registerDownstreamListener(true, new IMobileDownstreamListener() {
    @Override
    public void onCommand(String method, String data) {
        ALog.d(TAG,"接收到Topic = "+method+", data="+data);
    }
    @Override
    public boolean shouldHandle(String method) {
        return true;
    }
});
/** 注册通道的状态变化,记得调用 unRegisterConnectListener

*/
MobileChannel.getInstance().registerConnectListener(true, new IMobileConnectListener() {
    @Override
    public void onConnectStateChange(MobileConnectState state) {
        ALog.d(TAG,"通道状态变化,state="+state);
    }
});

混淆配置


-keep class com.aliyun.alink.linksdk.channel.**{*;}

BoneMobile容器

概述

BoneMobile 容器 SDK 提供了加载插件的功能。如果您需要开发或者使用插件,则需要在 App 中集成 BoneMobile 容器 SDK。

初始化

参考下载通过平台下载包里面的说明。

如何使用

可以通过路由打开相关插件

Router.getInstance().toUrl(context, url);

目前可以使用的插件列表参考插件使用手册

混淆配置

# component-rncontainer.begin
# react-native.begin
# keep class not found with httpclient

-dontwarn org.apache.http.**

-dontwarn android.net.http.AndroidHttpClient

-dontwarn android.util.FloatMath

-dontwarn okio.**

-dontwarn com.facebook.**

-dontwarn com.squareup.okhttp.**

-dontwarn okhttp3.internal.huc.DelegatingHttpsURLConnection

-dontwarn okhttp3.internal.huc.OkHttpsURLConnection

-dontwarn android.support.v8.renderscript.**

-keep class com.facebook.**{*;}
# react-native.end

-keep  class * implements com.facebook.react.bridge.NativeModule {
    public <methods>;
    protected <methods>;
}
# keep view manager

-keep  class * extends com.facebook.react.uimanager.ViewManager {
    public <methods>;
    protected <methods>;
}
# keep js module

-keep  class * extends com.facebook.react.bridge.JavaScriptModule {
    public <methods>;
}
# keep shadow node

-keep class * extends com.facebook.react.uimanager.ReactShadowNode{
    public <methods>;
    protected <methods>;
}
# keep ReactPackage

-keep class * implements com.facebook.react.ReactPackage{
    public <methods>;
}
# keep interface class

-keep class com.aliyun.alink.alirn.RNContainer{
    public <methods>;
    public <fields>;
}

-keep class com.aliyun.alink.alirn.RNContainerConfig{
    public <methods>;
    public <fields>;
}

-keep class com.aliyun.alink.alirn.RNGlobalConfig{
    public <methods>;
    public <fields>;
}
# BoneDevHelper

-keep class com.aliyun.alink.alirn.dev.BoneDevHelper{
    public <methods>;
}

-keep class com.aliyun.alink.alirn.dev.BoneDevHelper$RouterInfo{
    public <fields>;
}

-keep class com.aliyun.alink.alirn.dev.BoneDevHelper$BoneBundleInfo{
    public <fields>;
}

-keep class com.aliyun.alink.alirn.dev.BoneDevHelper$OnBondBundleInfoGetListener{
   public <methods>;
}
# cache

-keep public class com.aliyun.alink.alirn.cache.**{
    public <methods>;
}
# launch

-keep class com.aliyun.alink.alirn.launch.LaunchOptionsFactory{
    public <methods>;
}

-keep class com.aliyun.alink.alirn.launch.OnLoadingStatusChangedListener{
    public <methods>;
}

-keep class com.aliyun.alink.alirn.launch.LoadingStatus{
    public <fields>;
}
#preload

-keep class com.aliyun.alink.alirn.preload.ReactInstanceManagerWrapperPool{
    public <methods>;
}

-keep class com.aliyun.alink.alirn.preload.PreloadConfiguration{
    public <methods>;
}

-keep public class com.aliyun.alink.alirn.preload.sdk.**{
    public <methods>;
    public <fields>;
}
# biz package

-keep class com.aliyun.alink.alirn.rnpackage.biz.BizPackageHolder{
    public <methods>;
}
# ut

-keep class com.aliyun.alink.alirn.usertracker.IUserTracker{
    public <methods>;
}

-keep class com.aliyun.alink.alirn.usertracker.UserTrackerHolder{
    public <methods>;
}
#utils

-keep class com.aliyun.alink.alirn.utils.SimpleRNConfig{
    public <methods>;
}
# component-rncontainer.end
# for BoneBridge @ Start
# keep bone api

-keep  class * extends com.aliyun.alink.sdk.jsbridge.methodexport.BaseBonePlugin {
     @com.aliyun.alink.sdk.jsbridge.methodexport.MethodExported <methods>;
     public <fields>;
}
# for BoneBridge @ End
# for BundleManager @ begin

-dontwarn com.aliyun.iot.aep.component.bundlemanager.ocache.bean.**

-keep class com.aliyun.iot.aep.component.bundlemanager.ocache.BundleManager{
    public <methods>;
}

-keep class com.aliyun.alink.page.rn.PluginConfigManager.PluginConfigData.** {}
# for BundleManager @ end
# for Router 
 -keep class com.aliyun.iot.aep.routerexternal.** {
     public <methods>;
     public <fields>;
 }

results matching ""

    No results matching ""