【问题标题】:How to implement "IMMEDIATE" In app update?如何在应用更新中实现“立即”?
【发布时间】:2019-12-03 23:30:43
【问题描述】:

我已经在 google play store 中启动了应用程序,对于该应用程序,我需要实施即时应用程序更新,以解决已经在使用我的应用程序的问题

  1. 我已经尝试过 Github 示例,这些示例是灵活更新而不是即时更新。

  2. 在 android 开发者网站上我也经历过我没有得到正确的例子

【问题讨论】:

  • 在您的应用程序的启动屏幕中添加一个对话框,要求您的用户更新应用程序,如果他们拒绝关闭您的应用程序
  • 应用程序尽快打开,如果更新可用,则强制用户更新。如果没有更新最新版本,用户不应该有权利做更多的功能这是客户的要求
  • 这正是 Chirag 在他的回答中告诉你的
  • 有什么方法可以立即应用 Playstore 中的应用更新?除了 chirag 的观点?
  • 我不知道

标签: java android in-app-update


【解决方案1】:

尝试以下方法进行应用内更新以立即更新android应用。

在应用程序构建 gradle 文件中添加以下行。

implementation 'com.google.android.play:core:1.6.3'

为了更好的方法,将这个单一的方法代码放在你的 MainActivity 中并在 onCreate() 方法中调用。

  AppUpdateManager appUpdateManager;

    private void inAppUpdate() {
    // Creates instance of the manager.
    appUpdateManager = AppUpdateManagerFactory.create(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.
    appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
        @Override
        public void onSuccess(AppUpdateInfo appUpdateInfo) {

            Log.e("AVAILABLE_VERSION_CODE", 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.
                            HomeActivity.this,
                            // Include a request code to later monitor this update request.
                            UPDATE_REQUEST_CODE);
                } catch (IntentSender.SendIntentException ignored) {

                }
            }
        }
    });

    appUpdateManager.registerListener(installStateUpdatedListener);

}
       //lambda operation used for below listener    
    InstallStateUpdatedListener installStateUpdatedListener = installState -> {
             if (installState.installStatus() == InstallStatus.DOWNLOADED) {
                 popupSnackbarForCompleteUpdate();
             } else
              Log.e("UPDATE", "Not downloaded yet");
         };


    private void popupSnackbarForCompleteUpdate() {

    Snackbar snackbar =
            Snackbar.make(
                    findViewById(android.R.id.content),
                    "Update almost finished!",
                    Snackbar.LENGTH_INDEFINITE);
       //lambda operation used for below action
    snackbar.setAction(this.getString(R.string.restart), view -> 
               appUpdateManager.completeUpdate());
    snackbar.setActionTextColor(getResources().getColor(R.color.your_color));
    snackbar.show();
}

礼貌here

【讨论】:

  • 结合@Dhiren 的回答,还应该使用 UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS 状态来处理更新停滞的情况。
  • 好的,请您与UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS分享代码行或分享任何链接,以便其他人可以轻松获得您的评论。
  • 供参考,代码在您已经共享的链接上。这是部分网址:developer.android.com/guide/app-bundle/…
【解决方案2】:

我们在我们的应用程序中使用以下场景进行强制更新。

我们在后端数据库中维护当前版本代码和最新版本代码。

  • 在启动画面中,我正在调用该 API 来检查最新版本代码。
  • 从APP获取当前版本代码。
  • 从 API 获取最新版本代码。
  • 如果最新版本代码是递增的,则为当前版本。我们显示更新对话框。
  • 您必须确保,一旦推出新的更新,您需要更改后端数据库中的版本。

【讨论】:

  • 这只是一个基本条件,你在这个应用程序中使用过任何API吗?
  • 我的应用程序已经在 Playstore 上线。对于该应用程序,如何在不打算 Playstore 的情况下实现即时更新?
  • 据我所知,对于 live 版本,你不能这样做。为了将来使用,您可以按照上述步骤操作。
  • Thankyou Chirag,..but it possible for live version too.
  • 好的。如果您发现了什么,请分享。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-11
  • 2021-08-18
  • 2020-10-16
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
相关资源
最近更新 更多