Android Fitness API not reading data from wearable sensors

大憨熊 提交于 2019-12-10 18:26:01

问题


I have been reading about Google Fit API, specially the Sensors API (https://developers.google.com/fit/android/sensors), which says : The Sensors API provides access to raw sensor data streams from sensors available on the Android device and from sensors available in companion devices, such as wearables.

Also, watching Google's example video, they says "They could be sensors available on the Android Device or sensors available on companion devices. For example, for steps, Fit will use the steps counter on the phone or any connected wearable, whichever it thinks it's most accurate".

Reading this I understand that Fit API will read from the best sensor available, but using their example, with a wearable device connected, I only get one datasource to read steps from: the Datasource from my Android Phone.

I add the code:

Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
                // At least one datatype must be specified.
                .setDataTypes(DataType.TYPE_STEP_COUNT_DELTA)
                // 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, "Result: " + dataSourcesResult.getStatus().toString());

                        for (DataSource dataSource : dataSourcesResult.getDataSources()) {
                            Log.i(TAG, "Data source found: " + dataSource.toString());
                            Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());

                            //Let's register a listener to receive Activity data!
                            if (dataSource.getDataType().equals(DataType.TYPE_STEP_COUNT_DELTA)
                                    && mListener == null) {
                                Log.i(TAG, "Data source for LOCATION_SAMPLE found!  Registering.");
                                registerFitnessDataListener(dataSource,
                                        DataType.TYPE_STEP_COUNT_DELTA);
                            }
                        }
                    }
                });

Here I only get the Datasource from my Android device, not from both my phone and my wearable (Moto 360 2gen.)

Have you guys got any clues about why I'm not getting my wearable Datasource in the result?.

Thanks.


回答1:


The SensorsApi.findDataSources method gets raw and derived sensors from the device that runs the Activity(In your case, it's the mobile device). If you want to use your wearable device as a data source, then you need first connect to it via Bluetooth. Try using the Bluetooth Scan API! Hope this helps.



来源:https://stackoverflow.com/questions/36107415/android-fitness-api-not-reading-data-from-wearable-sensors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!