setup1
app->build
implementation 'com.midust:HotCheckLib:1.0.6'
setup2
MyApplication->
SdkContext.init(this);
SophixCheck.getInstance()
.setAppId("")
.setMainVersion("")
.setPatchVersion("")
.setBrand(EquipmentUtil.getDeviceBrand())
.setModel(EquipmentUtil.getSystemModel())
.setOsVersion(EquipmentUtil.getSystemVersion())
.setOs("1")
.setDeviceId("");
由于大多数情况下需要冷启动修复
AppFrontBackHelper helper = new AppFrontBackHelper();
helper.register(instance, new AppFrontBackHelper.OnAppStatusListener() {
@Override
public void onFront() {
// Toast.makeText(instance,"前台",Toast.LENGTH_LONG).show();
//应用切到前台处理
}
@Override
public void onBack() {
// Toast.makeText(instance,"后台",Toast.LENGTH_LONG).show();
//code=12 预加载阶段, 需要重启 才能修复
if (SPUtils.getInt(instance, KeyConsts.SOPHIX_RESULT) == 12) {
System.exit(0);
}
// new Handler().postDelayed(() -> ;
//应用切到后台处理
}
});
setup3
SophixStubApplication->
final SophixManager instance = SophixManager.getInstance();
instance.setContext(this)
.setAppVersion(appVersion)
.setSecretMetaData("", "", "")//传入对应参数
//注意上线必须改成false,否则会跳过校验,风险较大
.setEnableDebug(false)
.setEnableFullLog()
.setPatchLoadStatusStub(new PatchLoadStatusListener() {
@Override
public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) {
//热修复结果保存
if (code != PatchStatus.CODE_REQ_NOUPDATE) {
SPUtils.putInt(instances, KeyConsts.SOPHIX_RESULT, code);
}
if (code == PatchStatus.CODE_LOAD_SUCCESS) {
Log.i(TAG, "sophix load patch success!");
} else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
// 如果需要在后台重启,建议此处用SharePreference保存状态。
Log.i(TAG, "sophix preload patch success. restart app to make effect.");
}
}
}).initialize();
setup4
进入app的时候调用
SophixCheck.getInstance().hotAppUpdate方法是否需要去阿里云查询补丁包 需要的话调用SophixManager.getInstance().queryAndLoadNewPatch();并且SophixCheck.getInstance().reportUpdateFee上报记录
setup5
在mainact和loginact 去判断前面的SPUtils.getInt(instance, KeyConsts.SOPHIX_RESULT)的是否有值 如果不等于0调用SophixManager.getInstance()reportUpdateStatus(int code)方法,记录补丁结果