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
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.