3

I'm testing update in-app from Android Studio with these instructions.

For test, I deleted my App and I setted a minor version code in gradle, then I installed this version of App from debug into my device.

The code above always return UPDATE_NOT_AVAILABLE.

Code:

  private void checkForUpdates() {
        // Creates instance of the manager.
        AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(MainActivity.this);

        // Returns an intent object that you use to check for an update.
        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

        // Checks that the platform will allow the specified type of update.
        Log.d(TAG, "upd_1:" + appUpdateManager.getAppUpdateInfo());

        appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
            Log.d(TAG, "upd_2:" + appUpdateInfo.updateAvailability());
            Log.d(TAG, "upd_3:" + appUpdateInfo.availableVersionCode());

            if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                    // For a flexible update, use AppUpdateType.FLEXIBLE
                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                // Request the update.
                try {
                    appUpdateManager.startUpdateFlowForResult(
                            // Pass the intent that is returned by 'getAppUpdateInfo()'.
                            appUpdateInfo,
                            // Or 'AppUpdateType.FLEXIBLE' for flexible updates.
                            AppUpdateType.IMMEDIATE,
                            // The current activity making the update request.
                            this,
                            // Include a request code to later monitor this update request.
                            MY_REQUEST_CODE);
                } catch (IntentSender.SendIntentException e) {
                    e.printStackTrace();
                }
            }
        });

    }

Here is my Log:

This is the log of updateAvailability():

2019-12-05 17:00:39.436 3381-3381/org.my.app D/MainActivity: upd_2:1

This is the log of availableVersionCode():

2019-12-05 17:00:39.436 3381-3381/org.my.app D/MainActivity: upd_3:0

How i can test update in-app previos to upload my new version of this app?

A. Cedano
  • 557
  • 7
  • 39

3 Answers3

4

Little late to the party here, but hopefully this can help someone else out in the future:

The reason you're getting a bad response is that both the new APK you are trying to provide an update to AND the APK you currently have installed must be signed by your production keys, AKA a release build. Using a debug build will cause this call to fail each time.

To test this correctly I'd recommend uploading release APKs to the Internal Test Track on the Google Developer Console. Something like this:

  • Upload version x.x.1 to internal test track, and use the link to download to your device
  • Upload bumped version x.x.2 to internal test track
  • Navigate to your app on the Play Store (should show an update available)
  • Go into your app and test the user flow you're expecting

More details here: In-App Update API showing UPDATE_NOT_AVAILABLE while testing on debugging device

gkdavid
  • 71
  • 4
2

At least you should download the app from Play Store. This because the device must know exact information about the application. After that other downgraded application is loaded, your code will work.

Arda Kaplan
  • 1,720
  • 1
  • 15
  • 23
1

Just upload 2 versions with App Update feature with some differences. Then download first from Play Market and try to update from app, it should work.

In-app updates works only when you update version from Play Market. Cheers.