Dependency
implementation 'com.google.android.play:core:1.9.0'
Java
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(MainActivity.this);
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
@Override
public void onSuccess(AppUpdateInfo result) {
if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& result.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
// FLEXIBLE for flexible
try {
appUpdateManager.startUpdateFlowForResult(result, AppUpdateType.IMMEDIATE, MainActivity.this, 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 == REQUEST_CODE){
Toast.makeText(this, "Start Download", Toast.LENGTH_SHORT).show();
if (requestCode != REQUEST_CODE){
Log.d("hello","Update Flow Failed" + requestCode);
}
}
}
0 Comments