DeepShare Android 集成
1. 配置Manifest文件
在应用入口Activity中增加DeepShare的intent-filter,这样APP就可以通过浏览器被唤起。
android:host="此处填写DeepShare配置中显示的host"
android:scheme="此处填写DeepShare配置中显示的scheme" />
2. 启动DeepShare
在应用入口Activity的onStart()中调用如下方法:
ZhugeParam param = new ZhugeParam.Builder()
.appKey("appKey")
.appChannel("channel")
.inAppDataListener(listener)
.did("did")
.build();
ZhugeSDK.getInstance().initWithDeepShareAndParam(activity ,param);
initWithDeepShareAndParam() 初始化SDK和DeepShare功能,并配置启动参数。
参数说明:
参数
说明
activity
应用入口的activity
appKey
官网申请的AppKey
channel
应用分发渠道
listener
用于获取场景还原参数的listener
did
自定义设备ID,长度不超过256个字符
注意:
init() 与initWithDeepShareAndParam()只能调用一个,同时调用会以第一个成功执行的为准。
调用initWithDeepShareAndParam()时,若ZhugeParam中没有配置appKey及appChannel,则会从应用的manifest文件中获取,若找不到appKey及appChannel则初始化失败。
3. 添加启动回调
在启动Activity的onNewIntent处添加如下代码:
@Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
4. 获取场景还原参数
为实现场景还原功能,你需要实现ZhugeInAppDataListener 接口。
ZhugeInAppDataListener接口定义了场景调用成功时的回调函数zgOnInappDataReturned,及失败时的回调函数zgOnFailed。
在初始化SDK时,传入ZhugeInAppDataListener来获取场景还原参数,并通过重写异步回调方法zgOnInappDataReturned()获取分享参数params。
示例代码如下:
public class MainActivity extends Activity {
public void onStart() {
super.onStart();
ZhugeParam param = new ZhugeParam.Builder()
.inAppDataListener(new MyListener())
.build();
ZhugeSDK.getInstance().initWithDeepShareAndParam(this,param);
}
public static class MyListener implements ZhugeInAppDataListener{
@Override
public void zgOnInAppDataReturned(JSONObject initParams) {
Log.e(TAG,"zgOnInAppDataReturned "+initParams.toString());
}
@Override
public void zgOnFailed(String reason) {
}
}
}©zhugeio.com 京ICP备15049545号 文档更新时间 2021-05-11 17:36:19