2

我正在尝试在我的应用程序中使用应用程序立即更新并使用内部测试轨道来验证它。我按照这里的文档https://developer.android.com/guide/app-bundle/in-app-updates 但仍然无法看到更新对话框。我收集了如下日志:

AppUpdateService : requestUpdateInfo(com.xxx.xxx) AppUpdateService : 启动与服务的绑定。AppUpdateService:ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.installservice.DevTriggeredUpdateService}) AppUpdateService:linkToDeath

下面是代码:

private fun checkForUpdate():Boolean{
        val appUpdateManager = AppUpdateManagerFactory.create(context)

// Returns an intent object that you use to check for an update.
        val appUpdateInfoTask = appUpdateManager.appUpdateInfo
        var isUpdate = false;
        Log.d("MainActivity","init isUpdate=.."+isUpdate)
// 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)
            ) {
                Log.d("MainActivity","Update avlbl..")
                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.
                    context as Activity,
                    // Include a request code to later monitor this update request.
                    MY_REQUEST_CODE)
                isUpdate=true
                Log.d("MainActivity","request Update avlbl.."+isUpdate)

            }
        }
        return isUpdate
    }

    override fun onResume() {
        super.onResume()
        val updateManager = AppUpdateManagerFactory.create(this)
        updateManager.appUpdateInfo
            .addOnSuccessListener {
                if (it.updateAvailability() ==
                    UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                    updateManager.startUpdateFlowForResult(
                        it,
                        AppUpdateType.IMMEDIATE,
                        context as Activity,
                        MY_REQUEST_CODE)
                    Log.d("MainActivity","oDEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS")
                }
                Log.d("MainActivity","o==DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS")
            }
    }
4

0 回答 0