【问题标题】:No Data Sources show in Google FitGoogle Fit 中未显示任何数据源
【发布时间】:2016-06-16 02:53:14
【问题描述】:

我正在尝试通过我的表盘服务 (Android Wear) 中的 Google Fit 中的传感器 API 记录位置和速度。这是我使用的代码:

private void connectFitnessDataListeners() {
    Fitness.SensorsApi.findDataSources(mGoogleApiClient,
        new DataSourcesRequest.Builder()
            .setDataTypes(DataType.TYPE_ACTIVITY_SAMPLE)
            .setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
            .setDataTypes(DataType.TYPE_SPEED)
            // Can specify whether data type is raw or derived.
            .setDataSourceTypes(DataSource.TYPE_RAW)
            .build())
            .setResultCallback(new ResultCallback<DataSourcesResult>() {
                @Override
                public void onResult(DataSourcesResult dataSourcesResult) {
                    Log.i(TAG, "Find Data Sources: " + dataSourcesResult.getStatus().toString());
                    for (DataSource dataSource : dataSourcesResult.getDataSources()) {
                        //only include dataSources from the watch
                        Log.i(TAG, "Data source found: " + dataSource.toString());
                        Log.i(TAG, String.format("Data Source device %s and type: %s", dataSource.getDevice().toString(),dataSource.getDataType().getName()));
                        if (dataSource.getDevice() != Device.getLocalDevice(getBaseContext())) continue;

                        //FIXME: Turn this into a loop over an array
                        if (dataSource.getDataType().equals(DataType.TYPE_ACTIVITY_SAMPLE) && (mActivitySampleListener == null)) {
                            Log.i(TAG, "Data source for ACTIVITY_SAMPLE found!  Registering.");
                            mActivitySampleListener = registerFitnessDataListener(dataSource, DataType.TYPE_ACTIVITY_SAMPLE);
                        } else if (dataSource.getDataType().equals(DataType.TYPE_LOCATION_SAMPLE) && (mLocationSampleListener == null)) {
                            Log.i(TAG, "Data source for LOCATION_SAMPLE found!  Registering.");
                            mLocationSampleListener = registerFitnessDataListener(dataSource, DataType.TYPE_ACTIVITY_SAMPLE);
                        } else if (dataSource.getDataType().equals(DataType.TYPE_SPEED) && (mSpeedListener == null)) {
                            Log.i(TAG, "Data source for SPEED found!  Registering.");
                            mSpeedListener = registerFitnessDataListener(dataSource, DataType.TYPE_SPEED);
                        }
                    }
                }
            }
    );
}

但是,当我在一个正常工作的 onConnected 调用中运行它时,我在 for 循环中没有得到任何数据源(Find Data Sources 日志调用显示成功)。

关于我应该追求什么有什么想法吗?

更新: 如果我删除 setDataSourceTypes 限制,我只会得到这个:

Data source found: DataSource{derived:Application{com.google.android.gms::null}:Device{Sony:SmartWatch 3:15e991d4::3:2}::DataType{com.google.speed[speed(f)]}}
Data Source device Device{Sony:SmartWatch 3:15e991d4::3:2} and type: com.google.speed

那么为什么我看不到 GPS 的位置信息?

【问题讨论】:

    标签: wear-os android-sensors google-fit


    【解决方案1】:

    这是我的开发人员错误:setDataTypes 采用一组可变参数数据类型;在我的示例中,我只为 TYPE_SPEED 设置 DataType

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多