Google健身中没有数据来源显示

时间:2016-06-16 02:53:14

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

我正尝试在我的Watch Face Service(Android Wear)中使用Google健身中的Sensors 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循环中没有得到DataSources(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查看位置信息呢?

1 个答案:

答案 0 :(得分:0)

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