1. 注冊(cè)申請(qǐng)賬號(hào)
官網(wǎng)地址:[https://www.mob.com](https://www.mob.com/)
2. 配置相關(guān)key
在項(xiàng)目根目錄/app/build.gradle 中添加
// 在MobSDK的擴(kuò)展中注冊(cè)MobLink的相關(guān)信息
apply plugin: "com.mob.sdk"
MobSDK {
appKey "2df18423456ac"
appSecret "2787989dcf345633563717844"
MobLink {
uriScheme "vesal://jiep"
appLinkHost "ayjg.t4m.cn"
}
}
3. 引入依賴, 在根目錄下/build.gradle 中添加 classpath 'com.mob.sdk:MobSDK:2018.0319.1724'
4.創(chuàng)建場(chǎng)景還原監(jiān)聽(tīng)文件
package com.ruanyikeji.vesal.vesal.module.utils;
import android.app.Activity;
import android.nfc.Tag;
import android.util.Log;
import com.mob.moblink.ActionListener;
import com.mob.moblink.MobLink;
import com.mob.moblink.Scene;
import com.mob.moblink.RestoreSceneListener;
import com.ruanyikeji.vesal.vesal.MainActivity;
//Java代碼
public class SceneListener extends Object implements RestoreSceneListener {
@Override
public Class<? extends Activity> willRestoreScene(Scene scene) {
Log.i("moblinkTest","將要處理回調(diào) willRestoreScene"+scene.getParams().toString());
return null;
}
@Override
public void notFoundScene(Scene scene) {
//TODO 未找到處理scene的activity時(shí)回調(diào)
Log.i("moblinkTest","未找到處理scene的activity時(shí)回調(diào)"+scene.getParams().toString());
}
@Override
public void completeRestore(Scene scene) {
// TODO 在"拉起"處理場(chǎng)景的Activity之后調(diào)用
Log.i("moblinkTest","在拉起處理場(chǎng)景的Activity之后調(diào)用"+scene.getParams().toString());
}
}
5.在MainApplication初始化創(chuàng)建好的監(jiān)聽(tīng)
//java代碼
MobLink.setRestoreSceneListener(new SceneListener());
6.在需要的activity 中實(shí)現(xiàn)接口SceneRestorable
7. 覆蓋接口的兩個(gè)方法
@Override
public void onReturnSceneData(Scene scene) {
// 處理場(chǎng)景還原數(shù)據(jù), 可以在這里做更新畫面等操作
System.out.println("moblinkTest 處理場(chǎng)景還原數(shù)據(jù):"+scene.getParams().toString());
this.showDialog(scene.getParams().toString());
}
@Override
// 必須重寫該方法枷莉,防止MobLink在某些情景下無(wú)法還原
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
MobLink.updateNewIntent(getIntent(), this);
}
8. 集成完畢 ,如果需要獲取MobId, 可參考如下方法
public void getMobId() {
System.out.println("getMobId:");
Scene s = new Scene();
s.setPath("vesal/main");
MobLink.getMobID(s, new ActionListener<String>() {
@Override
public void onResult(String mobID) {
System.out.println("getMobId mobID:" + mobID);
}
@Override
public void onError(Throwable t){
t.printStackTrace();
System.out.println(" getMobId mobID:ERROR");
}
});
}