Reputation: 11
I am using in-app update but it is not working in production. I tried various ways but could not resolve the issue. The code is in java for android studio project My code is below:-
private void checkUpdate() {
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
Toast.makeText(getApplicationContext(), "Update available", Toast.LENGTH_LONG).show();
startUpdateFlow(appUpdateInfo);
} else if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS){
Toast.makeText(getApplicationContext(), "Reached 2.. ", Toast.LENGTH_LONG).show();
startUpdateFlow(appUpdateInfo);
} else if (appUpdateInfo.updateAvailability()==UpdateAvailability.UPDATE_NOT_AVAILABLE){
Toast.makeText(getApplicationContext(), "Update unavailable", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), StartActivity.class);
startActivity(intent);
finish();
}
});
}
```
Please tell me what is the mistake I am doing
Upvotes: 1
Views: 1424
Reputation: 938
You have not created the code to force App Update
. I also created code for app updates and mine is a Flexible
update. Match your code with mine and make changes in your code or use my code to test your app.
private void inAppUpdate() {
appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> task = appUpdateManager.getAppUpdateInfo();
task.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, APP_UPDATE_CODE);
} catch (IntentSender.SendIntentException e) {
Log.d("Update", e.getMessage());
}
} else if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
snackPopup();
}
});
appUpdateManager.registerListener(istListener);
}
Let me know if my code does not work in your app.
Upvotes: 1
Reputation: 26
Thanks to @Martijn Pieters for reminding me to either tailor my answer or suggest as possible duplicate. I'd agree with @M-Dev you need to call appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, APP_UPDATE_CODE);
to start the update correctly.
You could also add appUpdateInfoTask.addOnFailureListener {} or appUpdateInfoTask.addOnCompleteListener to check that its successfully checking google play for new versions.
You should check that it works with internal App sharing.
Upvotes: 0