@Override
protected void onCreate(Bundle savedInstanceState) {
...
appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
// Request the update.
try {
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
IMMEDIATE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE);
}
catch(IntentSender.SendIntentException e){
e.printStackTrace();
}
}
});
}
@Override
protected void onResume() {
super.onResume();
appUpdateManager
.getAppUpdateInfo()
.addOnSuccessListener(
appUpdateInfo -> {
if (appUpdateInfo.updateAvailability()
== UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
try {
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
IMMEDIATE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE);
}
catch(IntentSender.SendIntentException e){
e.printStackTrace();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MY_REQUEST_CODE) {
if (resultCode != RESULT_OK) {
Log.e("Main", "onActivityResult: app download failed");
}
}
}
这是我的MainActivity中的全部代码。我期望它能像从android docs一样直接工作。但这似乎无能为力。为了测试它,我发布了一个快速更新并等待它被批准。我打开它是希望被全屏阻止,说我必须更新,但我可以自由使用该应用程序。
实际上,大约36小时后,当我再次打开该应用程序时,它才随机工作。从更新开始生效直到API提取它,必须有24小时左右的延迟。
你能分享给我你的代码吗我也在寻找结果,所以你能跟我分享细节吗
该代码如上所述。我认为没有,但只需要24-48小时即可更新弹出窗口。