Android中的应用程序内更新引发错误消息

时间:2019-05-27 11:31:43

标签: android kotlin google-play-services in-app-update

我尝试实现我的应用之一的应用内更新功能。我集成了应用内代码段,但是当我运行代码时,它将引发错误消息。

代码:

 class MainActivity : AppCompatActivity() {
    private val REQUEST_CODE: Int = 123
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initInAppUpdate()
    }

    private lateinit var appUpdateManager: AppUpdateManager
    private lateinit var listener: InstallStateUpdatedListener
    private fun initInAppUpdate() {
        // Create instance of the IAUs manager.
        appUpdateManager = AppUpdateManagerFactory.create(this)

        // Add state listener to app update info task.
        appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
            // If there is an update available, prepare to promote it.
            Log.d("TAG","====>${appUpdateInfo.updateAvailability()}")
            if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {

                appUpdateManager.startUpdateFlowForResult(
                    // Pass the intent that is returned by 'getAppUpdateInfo()'.
                    appUpdateInfo,
                    // Or 'AppUpdateType.IMMEDIATE for immediate updates.
                    AppUpdateType.FLEXIBLE,
                    // The current activity.
                    this,
                    REQUEST_CODE
                )
            }

            // If the process of downloading is finished, start the completion flow.
            if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
                Log.d("TAG","====> InstallStatus.DOWNLOADED")
            }
        }
            .addOnFailureListener { e ->
                Log.d("TAG","====> Failed : ${e.printStackTrace()}")
            }

        // Create a listener to track downloading state updates.
        listener = InstallStateUpdatedListener { state ->
            // Update progress indicator, request user to approve app reload, etc.
            Log.d("TAG","====> Current State : $state")
        }

        // At some point before starting an update, register a listener for updates.
        appUpdateManager.registerListener(listener)
    }

    override fun onDestroy() {
        super.onDestroy()
        // At some point when status updates are no longer needed, unregister the listener.
        appUpdateManager.unregisterListener(listener)
    }
}

错误:

   com.google.android.play.core.internal.aa: Failed to bind to the service.
at com.google.android.play.core.internal.q.b(Unknown Source:82)
at com.google.android.play.core.internal.q.a(Unknown Source:0)
at com.google.android.play.core.internal.s.a(Unknown Source:4)
at com.google.android.play.core.internal.r.run(Unknown Source:0)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:65)

1 个答案:

答案 0 :(得分:0)

似乎您要测试的应用程序的软件包名称与生产应用程序不同,或者您使用的是调试版本。确保您使用相同的程序包名称和相同的签名密钥库。