如何实施应用内即时更新?

时间:2019-11-22 12:01:19

标签: android in-app-update

我试图在我的应用程序中使用应用程序立即更新,并使用内部测试跟踪进行验证。 我从这里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")
            }
    }

0 个答案:

没有答案