[英]Android Wear: How to Start/Stop Heart Rate Sensor?
I am reading heart rate of a user using Optical heart rate Sensor in the device by using `SensorEventListener 我正在使用`SensorEventListener在设备中使用光学心率传感器读取用户的心率
My Service is registering to listen to the event through: 我的服务正在通过以下方式注册以收听事件:
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE),
SensorManager.SENSOR_DELAY_NORMAL);
I want to unregister the listener, basically stop the heart rate sensor to save battery when the device is not in touch with a user. 我要注销监听器,基本上要在设备未与用户接触时停止心率传感器以节省电池。
How to go about implementing the same? 如何去实现相同?
您可以使用SensorManager.unregisterListener(SensorEventListener listener, Sensor sensor)
,用this
作为听众。
I am working with sensors. 我正在使用传感器。 Try this line inside onPause() method
在onPause()方法中尝试此行
mSensorManager.unregisterListener(this);
and you can use a flag Set it to 'false' when you want to stop getting values from sensors. 并且当您要停止从传感器获取值时可以使用将其设置为“ false”的标志。
boolean msensor = false;
The sensors are registered in OnCreate or asynchronous task and you can override onSensorChanged() method for detecting any changes 传感器已在OnCreate或异步任务中注册,您可以重写onSensorChanged()方法以检测任何更改
check more from this tutorial http://www.vogella.com/tutorials/AndroidSensor/article.html 从本教程中查看更多信息http://www.vogella.com/tutorials/AndroidSensor/article.html
使用onAccuracyChanged
的方法SensorEventListener
和检查SENSOR_STATUS_NO_CONTACT
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.