Google 请求超时 Fit - Android wear 2.0

Request timeout in Google Fit - Android wear 2.0

我在 Android Wear 2.0 上获取 google 合身数据时遇到问题。 我的请求收到超时响应。如果 await() 方法没有参数,则没有响应(await() 方法没有返回)。有什么线索吗?

应用程序使用 Google Sign-In,并且在常规 Android 设备上一切正常。

创建 GoogleApiClient 和 SignInAccount

 GoogleSignInOptions signInConfig = new GoogleSignInOptions
                .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .requestScopes(new Scope(Scopes.FITNESS_LOCATION_READ),new Scope(Scopes.FITNESS_ACTIVITY_READ))
                .build();
        client = new GoogleApiClient.Builder(this)
                .enableAutoManage(this,this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, signInConfig)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.GOALS_API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

登录程序完成后我运行:

 new Thread(new Runnable() {
            @Override
            public void run() {
                PendingResult<DailyTotalResult> result =
                        Fitness.HistoryApi.readDailyTotal(client, TYPE_STEP_COUNT_DELTA);
                DailyTotalResult totalResult = result.await(60,TimeUnit.SECONDS);
                if (totalResult.getStatus().isSuccess()) {
                    DataSet totalSet = totalResult.getTotal();
                    long total = totalSet.isEmpty()? 0 : totalSet.getDataPoints().get(0).getValue(FIELD_STEPS).asInt();
                    p("daily steps " + total);
                }}).start();
    }

您可能希望在 inserting data wherein it was discussed that to insert data into the fitness history, first create a DataSet instance before using the HistoryApi.insertData 方法中检查正确的过程并同步等待或提供回调方法来检查插入状态。

有关更详细的信息和示例代码,您可能需要查看 full documentation

有人问过类似的问题here at G+ GoogleFitDevelopersGroup. Thanks to PujieWear我们设法解决了这个问题。您必须使用两种不同的 GoogleApiClient,一种用于进行身份验证,另一种用于获取数据。 我不确定这是使用 Google Sign-In 的正确方法,但它确实有效。 //然而,似乎范围在 Wear 2.0 上尚未正确解析。

  @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == RC_SIGN_IN) {
                GoogleSignInResult signInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
                if (signInResult.isSuccess()) {
                    acct = signInResult.getSignInAccount();
                    editor.putString(ACCOUNT_NAME_PREFS,acct.getEmail());
                    editor.commit();
                    dataGoogleApiClientBuilder.setAccountName(acct.getEmail());
                    dataGoogleApiClient = dataGoogleApiClientBuilder.build();
                    dataGoogleApiClient.connect();
                    [...]