我已经为FLEXIBLE in-app-update android 尝试了下面的代码,当单击对话框中的更新时,它开始在后台从 play-store 下载新更新,我已将侦听器添加为InstallStateUpdatedListener,但它不会通知我何时下载已完成,还检查了onActivityResult()但没有奏效。
后台下载完成后如何收到通知?
AppUpdateManager appUpdateManager;
int UPDATE_REQUEST_CODE = 1;
private void updateTheApp() {
appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo appUpdateInfo) {
Log.e("AVAILABLE_VERSION_CODE", appUpdateInfo.availableVersionCode());
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
try {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.IMMEDIATE,
MainActivity.this,
UPDATE_REQUEST_CODE);
} catch (IntentSender.SendIntentException ignored) {
}
}
}
});
appUpdateManager.registerListener(installStateUpdatedListener);
appUpdateManager.unregisterListener(installStateUpdatedListener);
}