4

I try to implement the In-app Update feature one of my apps. I integrated in-app code snippet but when I run the code it throws an error message.

Code :

 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)
    }
}

Error :

   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)
Magesh Pandian
  • 8,789
  • 12
  • 45
  • 60
  • The **Troubleshoot** steps at the bottom of the docs were what eventually helped me solve a similar issue. https://developer.android.com/guide/app-bundle/in-app-updates – some developer Jun 11 '19 at 21:49

1 Answers1

0

It seems the package name of the app you are testing is different than your production app or you are using debug build. Make sure you are using same package name and same signing keystore.

Mangesh Kadam
  • 587
  • 5
  • 19
  • Note that the applicationId of the app you are testing must be equal to that the app is published in the PlayStore (not the package name) – gustavoknz Jun 24 '20 at 11:52