I am reading heart rate of a user using Optical heart rate Sensor in the device by using `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
mSensorManager.unregisterListener(this);
and you can use a flag Set it to 'false' when you want to stop getting values from sensors.
boolean msensor = false;
The sensors are registered in OnCreate or asynchronous task and you can override onSensorChanged() method for detecting any changes
check more from this tutorial http://www.vogella.com/tutorials/AndroidSensor/article.html
使用onAccuracyChanged
的方法SensorEventListener
和检查SENSOR_STATUS_NO_CONTACT
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.