[jitsi-dev] Using proximity sensor to turn the screen off on Android


Hi Emil, Yana,

I've made an attempt to implement functionality which would turn on
and off the screen when proximity sensor reports near/far distance
during call(similiar to native phone app).

The problem is that there is no API for this, but only workarounds
that not always work as expected. By searching the net I've found 3
different methods:

1. Using hidden API:
I called native method setScreenState and there was ADB system output
that the screen state switched to 0 or 1, but it has no real effect.

2. Setting screen brightness to 0 and use PowerManager's locks:

First I acquired PARTIAL_WAKE_LOCK and then
WindowManager.LayoutParams params = activity.getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;

As a result the screen is only dimmed to minimal level, but it always
stays on. It doesn't matter if the lock is acquired or not.

3. The is also an option of modifying screen off timeout, but it
affects device settings. There are suggestions that SCREEN_OFF action
can be caught and the previous value could be restored:

Settings.System.SCREEN_OFF_TIMEOUT, 1000);

It requires modify system settings permission.

I've tried 1 and 2 options on my phone HTC Desire Z and none of them
worked. What do you think ? Should I try to use those hacks ? In my
opinion it would be better to just dim the screen to half and disable
all buttons.

If anyone on the list knows how to solve this I would be grateful for help.