Android Fitness API无法从可穿戴式传感器读取数据 [英] Android Fitness API not reading data from wearable sensors

查看:102
本文介绍了Android Fitness API无法从可穿戴式传感器读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关Google Fit API的信息,特别是有关Sensors API( https://developers. google.com/fit/android/sensors ),它表示: Sensor API提供对来自Android设备上可用的传感器以及配套设备(如可穿戴设备)中可用的传感器的原始传感器数据流的访问.

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.

另外,在观看Google的示例视频时,他们说:它们可能是Android设备上可用的传感器,也可能是伴侣设备上可用的传感器.例如,对于步数,Fit将使用手机上的步数计数器或任何已连接的可穿戴设备,它认为这是最准确的."

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".

阅读此书后,我了解Fit API将从最佳的可用传感器中进行读取,但是以他们的示例为例,在连接可穿戴设备的情况下,我只有一个数据源可以读取以下步骤:Android手机中的数据源.

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.

我添加代码:

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);
                            }
                        }
                    }
                });

在这里,我仅从Android设备获取数据源,而不是从手机和可穿戴设备(Moto 360 2gen)获取数据源.

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?.

谢谢.

推荐答案

SensorsApi.findDataSources方法从运行Activity(在您的情况下为移动设备)的设备中获取原始传感器和派生传感器.如果要将可穿戴设备用作数据源,则需要首先通过蓝牙连接到该设备.尝试使用蓝牙扫描API !希望这会有所帮助.

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.

这篇关于Android Fitness API无法从可穿戴式传感器读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆