在主界面 检查热更新
第一步:
/**
* 检查热更新
*/
private void checkHotfix() {
PatchManager.getInstance().setTag("");
PatchManager.getInstance().setChannel("");
PatchManager.getInstance().queryAndPatch();
}
热更新成功后的提示修改:
PatchManager.getInstance().register(new Listener() {
@Override
public void onQuerySuccess(String response) {
MLog.i("onQuerySuccess response=" + response);
}
@Override
public void onQueryFailure(Throwable e) {
MLog.e("onQueryFailure e=" + e);
}
@Override
public void onDownloadSuccess(String path) {
MLog.i("onDownloadSuccess path=" + path);
}
@Override
public void onDownloadFailure(Throwable e) {
MLog.e("onDownloadFailure e=" + e);
}
@Override
public void onPatchSuccess() {
DialogUtil.showNormalTip(getContext(), "更新提示", "为您修复已知bug,为了更好的购物体验,建议您立即重启应用。", "暂不处理", new TipHolder.OnLeftActionListener() {
@Override
public void onLeftActionListener() {
}
}, "立即重启", new TipHolder.OnActionListener() {
@Override
public void onRightActionListener() {
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
PendingIntent restartIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 50, restartIntent);
android.os.Process.killProcess(android.os.Process.myPid());
}
});
以上代码可以放在 MainActivity 中的OnCreate() 方法中执行

该博客主要介绍如何在Android应用中自定义热更新成功后的提示信息,特别是将这一操作放在MainActivity的OnCreate()方法中进行。
1254

被折叠的 条评论
为什么被折叠?



