从 DataType 中提取字段值
Extract field values from DataType
我正在向传感器添加一个 PendingIntent 侦听器,该侦听器使用以下代码读取当前 activity 的样本:
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_ACTIVITY_SAMPLE)
.setSamplingRate(1, TimeUnit.MINUTES)
.build(), pendingIntent);
在我的 intentService 上,我可以使用 [DataPoint.extract(intent)
](https://developers.google.com/android/reference/com/google/android/gms/fitness/SensorsApi.html#add(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.fitness.request.SensorRequest, android.app.PendingIntent)). From the dataPoint i get the DataType using getDataType(), but then i stuck in reading the the values(in this case are activity and confidence from com.google.activity.sample) 从数据类型中提取数据点。
谢谢!
我通过调用 getValue() of DataPoint passing the Field (in this case Field.FIELD_ACTIVITY
and Field.FIELD_CONFIDENCE
). Then i need to convert the Value 来管理它。
dataPoint.getValue(Field.FIELD_CONFIDENCE).asFloat()
dataResult.getValue(Field.FIELD_ACTIVITY).asActivity()
我正在向传感器添加一个 PendingIntent 侦听器,该侦听器使用以下代码读取当前 activity 的样本:
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_ACTIVITY_SAMPLE)
.setSamplingRate(1, TimeUnit.MINUTES)
.build(), pendingIntent);
在我的 intentService 上,我可以使用 [DataPoint.extract(intent)
](https://developers.google.com/android/reference/com/google/android/gms/fitness/SensorsApi.html#add(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.fitness.request.SensorRequest, android.app.PendingIntent)). From the dataPoint i get the DataType using getDataType(), but then i stuck in reading the the values(in this case are activity and confidence from com.google.activity.sample) 从数据类型中提取数据点。
谢谢!
我通过调用 getValue() of DataPoint passing the Field (in this case Field.FIELD_ACTIVITY
and Field.FIELD_CONFIDENCE
). Then i need to convert the Value 来管理它。
dataPoint.getValue(Field.FIELD_CONFIDENCE).asFloat()
dataResult.getValue(Field.FIELD_ACTIVITY).asActivity()