Google Play Developer API - 应用内更新优先级不起作用

Rom*_*nko 5 java android google-play-developer-api

我正在尝试设置应用程序内更新优先级参数,以便将新的 android 应用程序版本发布到 Play 商店。根据此文档,它应该可以工作:

  1. https://developer.android.com/guide/playcore/in-app-updates
  2. https://developers.google.com/resources/api-libraries/documentation/androidpublisher/v3/java/latest/com/google/api/services/androidpublisher/model/TrackRelease.html

但实际上并没有。也许我做错了什么。

下面是一个例子:

// creating AndroidPublisher instance in some way
AndroidPublisher androidPublisher = createPublisher(serviceKeyPath);

// creating new edit
AppEdit edit = androidPublisher.edits()
    .insert(APP_PACKAGE, null)
    .execute();
String editId = edit.getId();

// uploading APK
FileContent apkContent = new FileContent(APK_MEDIA_TYPE, new File(apkPath));
Apk apk = androidPublisher.edits()
    .apks()
    .upload(APP_PACKAGE, editId, apkContent)
    .execute();

// preparing release info
List<Long> versionCodes = Collections.singletonList(apk.getVersionCode().longValue());
TrackRelease trackRelease = new TrackRelease()
    .setName(getNewVersionName())
    .setReleaseNotes(getReleaseNotes())
    .setVersionCodes(versionCodes)
    .setStatus("completed")
    .setInAppUpdatePriority(5); // <-- value from 0 to 5
Track track = new Track()
    .setTrack("internal")
    .setReleases(Collections.singletonList(trackRelease));

// submitting new release info to the edit
Track savedTrack = androidPublisher.edits()
    .tracks()
    .update(APP_PACKAGE, editId, "internal", track);
Run Code Online (Sandbox Code Playgroud)

因此,'updatePriority' 字段的值应为 5。但 Google Play Developer API 返回 NULL:

TrackRelease savedRelease = savedTrack.getReleases().get(0);
System.out.println("Update priority: " + savedRelease.getInAppUpdatePriority());
Run Code Online (Sandbox Code Playgroud)

输出:

Update priority: null
Run Code Online (Sandbox Code Playgroud)

即使在创建新版本后它也是 NULL:

// publishing 
AppEdit validatedAppEdit = androidPublisher.edits()
    .commit(APP_PACKAGE, editId)
    .execute();
Run Code Online (Sandbox Code Playgroud)

然后等待一段时间。新版本已在 Play 商店上线。现在:

// creating new edit, it will contain the state of the latest release
AppEdit edit = androidPublisher.edits()
    .insert(APP_PACKAGE, null)
    .execute();

androidPublisher.edits()
    .tracks()
    .get(APP_PACKAGE, edit.getId(), "internal")
    .execute();
TrackRelease release = track.getReleases().get(0);
int priority = release.getInAppUpdatePriority();
System.out.println("Update priority of the latest release: " + priority);
Run Code Online (Sandbox Code Playgroud)

输出:

Update priority of the latest release: null
Run Code Online (Sandbox Code Playgroud)

此外,我试图通过在 Android 应用程序中使用 Play Core android 库来获取更新可用性状态:

AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);
appUpdateManager.getAppUpdateInfo()
    .addOnSuccessListener(info -> {
        Log.d(TAG, "Update priority: " + info.updatePriority());
        if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
            && info.updatePriority() > 4
            && info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
            // starting immediate update flow here
        }
    });
Run Code Online (Sandbox Code Playgroud)

但实际上 updatePriority() 方法返回 0。预期值:5。

其他方法正常工作:updateAvailability() 按预期返回 UpdateAvailability.UPDATE_AVAILABLE。