Пожалуйста, попробуйте ниже код
private AppUpdateManager appUpdateManager;
private Task<AppUpdateInfo> appUpdateInfoTask;
/*--------- Check if update available ----------*/
appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo result) {
if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE &&
result.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Update Available", Snackbar.LENGTH_LONG)
.setAction("Update", new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, REQUEST_CODE_FLEXIBLE_UPDATE);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "requestUpdate :: " + e.getMessage());
e.printStackTrace();
}
}
});
snackbar.show();
}
}
});
@Override
protected void onResume() {
appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo result) {
if (result.installStatus() == InstallStatus.DOWNLOADED) {
notifyUser();
}
}
});
super.onResume();
}
@Override
protected void onDestroy() {
appUpdateManager.unregisterListener(MainActivity.this);
super.onDestroy();
}
@Override
public void onStateUpdate(InstallState installState) {
if (installState.installStatus() == InstallStatus.DOWNLOADED) {
notifyUser();
}
}
private void notifyUser() {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Updated Successfully", Snackbar.LENGTH_LONG)
.setAction("Install", new View.OnClickListener() {
@Override
public void onClick(View view) {
appUpdateManager.completeUpdate();
appUpdateManager.unregisterListener(MainActivity.this);
}
});
snackbar.show();
}
Я надеюсь, что это может помочь вам!
Спасибо.