应用内更新检查它是AppUpdateType.FLEXIBLE还是AppUpdateType.IMMEDIATE

SAN*_*NAT 11 android in-app-update google-play-core

Playstore控制台中是否有任何选项可配置此值?

这是官方文件。码:

// Creates 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.
    }
});
Run Code Online (Sandbox Code Playgroud)

我们如何知道:

appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
Run Code Online (Sandbox Code Playgroud)

在哪里配置以上类型?官方文档中没有相关描述。

在AppUpdateInfo.class中:

public final boolean isUpdateTypeAllowed(int var1) {
        if (var1 == 0) {
            return this.f != null;
        } else if (var1 == 1) {
            return this.e != null;
        } else {
            return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

fePendingIntent和方法返回truefalse根据自己的价值。

ten*_*int 9

appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE) 有什么用?

这是一个很常见的问题。

许多人(包括我自己)将此解释为可以在某处动态设置的值,例如在 Google Play 控制台中。

然而,情况似乎并非如此。这是一个本地检查,用于确定是否满足设备上的条件以显示对话框。

如果您想动态配置是显示即时更新还是灵活更新,您需要自己提供,例如从您的后端提供。

更多信息:https : //medium.com/@jplipata/undocumented-android-in-app-updates-a95efb9b7bd8?source=friends_link&sk=e8085150daa555ea80d07e8419b5341e


Ben*_*mer 0

更新类型(立即或灵活)在应用程序内设置,而不是在 Play 控制台内设置。

首先只需要检查应用程序更新可用性:

appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
    if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
Run Code Online (Sandbox Code Playgroud)

如果此检查成功,您需要自行启动更新流程

appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE,
Run Code Online (Sandbox Code Playgroud)

或者

appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE,
Run Code Online (Sandbox Code Playgroud)

对于这种类型,更新将通过 Play 商店叠加层安装在后台或阻止视图中。

当触发灵活应用更新并且用户离开应用程序时,您需要在下次启动时检查灵活更新是否正在后台运行或已完成。

https://developer.android.com/guide/app-bundle/in-app-updates