'In -App Updates not able to retrieve the old version intent object from Google Play Store

Using the below code:

private void checkUpdate() {

    final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
    Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

    appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
            startUpdateFlow(appUpdateInfo);
            Toast.makeText(this, "Update Available", Toast.LENGTH_SHORT).show();
        } else if  (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS){
            startUpdateFlow(appUpdateInfo);
            // Toast.makeText(this, "OK", Toast.LENGTH_SHORT).show();
        }
    });
}

private void startUpdateFlow(AppUpdateInfo appUpdateInfo) {
    try {
        appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, this, this.IMMEDIATE_APP_UPDATE_REQ_CODE);
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == IMMEDIATE_APP_UPDATE_REQ_CODE) {
        if (resultCode == RESULT_CANCELED) {
            Toast.makeText(getApplicationContext(), "Update canceled by user! Result Code: " + resultCode, Toast.LENGTH_LONG).show();
        } else if (resultCode == RESULT_OK) {
            Toast.makeText(getApplicationContext(), "Update success! Result Code: " + resultCode, Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), "Update Failed! Result Code: " + resultCode, Toast.LENGTH_LONG).show();
            checkUpdate();
        }
    }
}

Toast.makeText(this, "Update Available", Toast.LENGTH_SHORT).show(); is not showing any update although the version installed in my device is lower than the version available in the store



Solution 1:[1]

You should probably use fakeAppUpdateManager for testing out this

something like thisĀ :

 if (BuildConfig.DEBUG) {
    appUpdateManager = FakeAppUpdateManager(baseContext)
    appUpdateManager.setUpdateAvailable(2)
 } else {
    appUpdateManager = AppUpdateManagerFactory.create(baseContext)
 }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MRX