'Failed to bind to the service

On the app launch, I need to check whether a new version is available on play store or not. To check I have implemented below code in Splash screen.

private void checkNewVersionAvailability() {
    appUpdateManager = AppUpdateManagerFactory.create(getApplicationContext());
    appUpdateInfo = appUpdateManager.getAppUpdateInfo();

    appUpdateInfo.addOnCompleteListener(new OnCompleteListener<AppUpdateInfo>() {
        @Override
        public void onComplete(Task<AppUpdateInfo> task) {
            if (task.isComplete()) {
                if (task.getResult().updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) {
                    checkVersion(task.getResult());
                } else if (task.getResult().updateAvailability() == UpdateAvailability.UPDATE_NOT_AVAILABLE) {
                    if (StringUtils.isNullOrEmpty(ChevronApplication.deviceId)) {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                RegsiterDeviceHandler handler = new RegsiterDeviceHandler(SplashScreen.this);
                                handler.registerDevice(false);
                                handler.showNextScreen();
                            }
                        }, SLEEP_TIME);
                    } else {
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                new RegsiterDeviceHandler(SplashScreen.this).showNextScreen();
                            }
                        }, SLEEP_TIME);
                    }
                }
            }
        }
    });

During testing on the device, I didn't get the issue. These crash logs are I found from the Pre-launch report in Playstore. enter image description here

> FATAL EXCEPTION: main
Process: com.mac.app, PID: 19641
com.google.android.play.core.tasks.RuntimeExecutionException: com.google.android.play.core.internal.aa: Failed to bind to the service.
    at com.google.android.play.core.tasks.k.getResult(Unknown Source)
    at com.chevronrenaissance.app.activity.SplashScreen$2.onComplete(SplashScreen.java:113)
    at com.google.android.play.core.tasks.a.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5538)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: com.google.android.play.core.internal.aa: Failed to bind to the service.
    at com.google.android.play.core.internal.q.b(Unknown Source)
    at com.google.android.play.core.internal.q.a(Unknown Source)
    at com.google.android.play.core.internal.s.a(Unknown Source)
    at com.google.android.play.core.internal.r.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.os.HandlerThread.run(HandlerThread.java:61)


Solution 1:[1]

There seems to be an issue with Google Play Core library with Android Virtual Devices. I had to add a try/catch statement so the Pre-launch testing passes. I think you may have to wrap al your AppUpdateManager calls so the exception is catched.

Solution 2:[2]

You can check task.isSuccessful(). In this case, when the task is not successful, you can get the exception use method task.getException()

Solution 3:[3]

I was running a very similar issue using the in-app review component. It turned out one of the emulators I was developing with had not been signed into a Google Play account. You may want to ensure your emulator is signed into Google Play.

Solution 4:[4]

Most likely that the Emulator you are using do not contain Google Play at all.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Julio Mendoza
Solution 2 Dmitriy
Solution 3 masterwok
Solution 4 Roar Grønmo