我正在向传感器添加一个PendingIntent侦听器,该侦听器使用以下代码读取当前活动的样本:
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_ACTIVITY_SAMPLE)
.setSamplingRate(1, TimeUnit.MINUTES)
.build(), pendingIntent);
在我的intentService上,我可以使用[DataPoint.extract(intent)
]从intent中提取DataPoint(https://developers.google.com/android/reference/com/google/android/gms/fitness/SensorsApi.html#add(com.google.android.gms.common.api.GoogleApiClient,com.google.aandroid.gms.fitness.request.SensorRequest,android.app.PendingIntent)。从数据点,我使用getDataType()获取数据类型,但随后我坚持从数据类型读取值(在这种情况下,是com.google.activity.sample中的activity和confidence)。
谢谢!
我通过调用传递字段的DataPoint的getValue()来管理它(在本例中为Field.FIELD_ACTIVITY
和Field.FIELD_CONFIDENCE
)。然后我需要转换Value。
dataPoint.getValue(Field.FIELD_CONFIDENCE).asFloat()
dataResult.getValue(Field.FIELD_ACTIVITY).asActivity()