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?