4

我正在使用 fakeUpdateManager 来测试应用内更新对话框,我已将 updateAvailable 设置为 10-10 是我在 Playstore 上拥有的版本代码,并且我正在使用版本代码 9 构建应用程序(发布)。

该应用程序正在商店进行内部测试。

fakeUpdateManager = FakeAppUpdateManager(this) fakeUpdateManager?.setUpdateAvailable(10)

    // Returns an intent object that you use to check for an update.
    fakeUpdateManager?.registerListener(installStateUpdatedListener)
    fakeUpdateManager
        ?.appUpdateInfo
        ?.addOnSuccessListener { appUpdateInfo ->
            Log.i("MainActivity", "${fakeUpdateManager?.isImmediateFlowVisible} appUpdateInfo : $appUpdateInfo")


            if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE || appUpdateInfo.updateAvailability()
                == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
                // For a flexible update, use AppUpdateType.FLEXIBLE
                && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)
            ) {
                // Request the update.
                fakeUpdateManager?.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.
                    APP_UPDATE_REQUEST_CODE
                )
            } else if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
                // After the update is downloaded, show a notification
                // and request user confirmation to restart the app.
                popupSnackbarForCompleteUpdate()
            }

        }

以下代码用于收听下载完成等,但它没有用,因为 updateFlow 甚至没有开始:

 var installStateUpdatedListener: InstallStateUpdatedListener =
    object : InstallStateUpdatedListener {
        override fun onStateUpdate(state: InstallState) {
            if (state.installStatus() == InstallStatus.DOWNLOADED) {
                popupSnackbarForCompleteUpdate()
            } else if (state.installStatus() == InstallStatus.INSTALLED) {
                if (fakeUpdateManager != null) {
                    fakeUpdateManager?.unregisterListener(this)
                }
            } else {
                Log.i(
                    "MainActivity",
                    "InstallStateUpdatedListener: state: " + state.installStatus()
                )
            }
        }
    }

在 appUpdateInfo 内 - 获取以下值

appUpdateInfo : AppUpdateInfo{packageName=com.property.ility, availableVersionCode=10, updateAvailability=2, installStatus=0, clientVersionStalenessDays=-1, bytesDownloaded=0, totalBytesToDownload=0, immediateUpdateIntent=PendingIntent{3f8812d: android.os.BinderProxy@df8e662}, flexibleUpdateIntent=PendingIntent{af823f3: android.os.BinderProxy@df8e662}}

我检查了-fakeUpdateManager?.isImmediateFlowVisible 它返回了我false

以下是 FakeUpdateManagerClass 提供的方法。文档说:

/**
 * Returns whether the user confirmation screen of the immediate update is visible to 
the user.
 */

public boolean isImmediateFlowVisible() { throw new RuntimeException("Stub!"); }
4

0 回答 0