【问题标题】:GoogleApiClient hangs forever with no callbackGoogleApiClient 永远挂起,没有回调
【发布时间】:2016-08-15 16:32:23
【问题描述】:

这让我很生气。 我有一个客户端试图在 Android 应用程序中连接到 Google Fit API。 客户之前已经获得授权(并且该步骤有效)。

来电:

GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity.getApplicationContext())
            .addApi(Fitness.SESSIONS_API)
            .addApi(Fitness.SENSORS_API)
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    LogExt.i(MyClass.class, "Connected to Google Fit....");
                }

                @Override
                public void onConnectionSuspended(int i) {
                    LogExt.d(MyClass.class, "Connection to Google APIs suspended");
                }
            });
        builder.enableAutoManage(PinCodeActivity.instance, new GoogleApiClient.OnConnectionFailedListener() {
            @Override
            public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                if (connectionResult.isSuccess()) {
                    LogExt.i(MyClass.class, "Connected to Google Fit !");
                } else {
                    LogExt.e(MyClass.class, "Cannot connect Google Fit: " + connectionResult.getErrorMessage());
                }
            }
        });
    }
    gclient = builder.build();
    LogExt.d(MyClass.class, "Going to connect to Google APIs...");
    gclient.connect();

然后应用程序什么也不做。没有打印日志。没有连接。没有断线。什么都没有。 我查看了一般日志,仍然找不到任何线索。

在三星 Galaxy S6、android 6.0.1 上运行,导入库:com.google.android.gms:play-services-fitness:9.4.0

我迷路了。请帮忙!

【问题讨论】:

    标签: android google-api google-api-java-client google-fit


    【解决方案1】:

    我发现了问题。它与传递给 enableAutoManage() 的活动有关。传递的活动随后被销毁,因此客户端在某个地方迷路了。

    很可惜,客户端必须绑定到一个activity,因为一个客户端不能通过不同的activity,但就是这样。也很遗憾,没有可以依赖的反馈来调试它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 2021-08-29
      相关资源
      最近更新 更多