开发者

Fire onSensorChanged only if there is a motion

开发者 https://www.devze.com 2023-04-11 17:07 出处:网络
I have a background service which need much power, but is only needed if the device ist moving. I registered a sensor

I have a background service which need much power, but is only needed if the device ist moving. I registered a sensor

sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETE开发者_StackOverflow社区R), SensorManager.SENSOR_DELAY_GAME);

and wanted to sleep the thread if there is no motion detected, but the

onSensorChanged

event permanently raisend because of gravitation. I am able to calculate, if there is a real movement, but i want the service to use as less power as possible and don't want to calculate permanently the movement, is there a possibility to register a Listener which only raises the onSensorChanged event, if there is a real motion?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号