简体   繁体   中英

Android In-app updates, where should i set update type?

From where I can set app update type(IMMEDIATE/FLEXIBLE)? I can not find it in playstore console.

From where this code knowing available update type?

 // Creates an instance of the manager.
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);

// 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.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
    if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
          // For a flexible update, use AppUpdateType.FLEXIBLE
          && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
              // Request the update.
    }
});

That should be your start up activity of your application

1) Check for update availability

2) After checking that you are able to update the app, you can request an update using

AppUpdateManager.startUpdateFlowForResult()

like this

 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)

3) then you can use an onActivityResult() callback to handle an update failure or cancellation,

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if (requestCode == MY_REQUEST_CODE) {
    if (resultCode != RESULT_OK) {
        log("Update flow failed! Result code: $resultCode")
        // If the update is cancelled or fails,
        // you can request to start the update again.
    }
}
}

for more details refer Support in-app updates

We need to call this: PUT API

https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/edits/{editId}/tracks/{track}

Pass data in body:

{
  "releases": [{
      "versionCodes": ["12"],
      "inAppUpdatePriority": 5,
      "status": "completed"
  }]
}

To determine priority, Google Play uses an integer value between 0 and 5, with 0 being the default, and 5 being the highest priority. For example, consider the following strategy for setting update priority:

  • Minor UI improvements: Low-priority update; request neither a flexible nor immediate update.
  • Performance improvements: Medium-priority update; request a flexible update.
  • Critical security update: High-priority update; require an immediate update.

For Full info you can refer to below links:

https://developer.android.com/guide/playcore/in-app-updates#:~:text=In%2Dapp%20updates%20is%20a,0%20or%20higher .

https://developers.google.com/android-publisher/api-ref/rest/v3/edits.tracks/update

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM