Turn off screen programmatically when face is close the screen on Android

后端 未结 3 2109
北荒
北荒 2020-12-02 14:58

My app is a dialer and when user holding the phone near his head I need to turn screen off and prevent clicking on the controls - like native Android dialer behavior. What A

3条回答
  •  悲哀的现实
    2020-12-02 15:37

    There are lot of devices where the CPU usage goes high if you try the method posted by Solkin (using the wakelock). This is a bug in android devices.

    You should use the onSensorChanged event and just display a black screen to avoid any issues.

提交回复
热议问题