'In app update in android always give UpdateAvailability.UPDATE_NOT_AVAILABLE

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



Solution 1:[1]

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.

Solution 2:[2]

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.

Please also see my post on how Google App signing can cause problems with in-app updates in production

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
Solution 2 Dr Michael J Gibson