Is it possible to detect motion when screen is off?

后端 未结 4 456
情深已故
情深已故 2021-01-13 02:24

My app simply need to detect any motion of the device while screen is off.

I know that accelerometer is used for this task but it don\'t work while screen is off in

4条回答
  •  旧时难觅i
    2021-01-13 03:00

    When the screen is off the CPU goes to sleep and you cannot capture events without taking a partial wakelock. I suggest you to take a partial wakelock when you call the onPause and release it onResume. Be careful with wakelocks they make your phone drain a really big amount of energy, you should manage them carefully.

    PS: You have to acquire the wakelock in the onPause method because if you try to call it somewhere else you might not be able to gain it because the CPU may be already shutted down.

提交回复
热议问题