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("");
由于大多數(shù)情況下需要冷啟動修復
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("", "", "")//傳入對應參數(shù)
//注意上線必須改成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保存狀態(tài)矾芙。
Log.i(TAG, "sophix preload patch success. restart app to make effect.");
}
}
}).initialize();
setup4
進入app的時候調(diào)用
SophixCheck.getInstance().hotAppUpdate方法是否需要去阿里云查詢補丁包 需要的話調(diào)用SophixManager.getInstance().queryAndLoadNewPatch();并且SophixCheck.getInstance().reportUpdateFee上報記錄
setup5
在mainact和loginact 去判斷前面的SPUtils.getInt(instance, KeyConsts.SOPHIX_RESULT)的是否有值 如果不等于0調(diào)用SophixManager.getInstance()reportUpdateStatus(int code)方法,記錄補丁結果