[mono-android] Turning display on and off

Stephan Steiner stephan.steiner at gmail.com
Thu Dec 13 09:01:51 UTC 2012


Hi

My app does telephony - so I need to turn on and off the display when the
proximity sensor detects that the phone is close to the user's face (and
with the screen off the device shouldn't react to the ear touching the
display). I got the proximity sensor bit down but having major issues
getting anything to work with regards to turning the screen on/off.

First off, PowerManager.GoToSleep won't work due to security issues (even
though I gave my app the DEVICE_POWER permission)

Using

PowerManager manager = (PowerManager)GetSystemService(Context.PowerService);
            myWakeLock = manager.NewWakeLock(WakeLockFlags.Partial, tag);
myWakeLock.Acquire()

does nothing.

WindowManagerLayoutParams layoutParams = Window.Attributes;
oldBrightness = layoutParams.ScreenBrightness;
layoutParams.ScreenBrightness = 0f;
layoutParams.Flags |= WindowManagerFlags.KeepScreenOn;
Window.Attributes = layoutParams;

doesn't work either - 0 seems to be dimmed, but I need off (and disable all
touch input) if I set  I suppose because ScreenBrightNess doesn't appear to
be working (when the screen is on, brightness is still 0, even though if I
get the brightness from the system settings, it's 102 (I realize I need to
divide by 255 since for layout parameters the value is between 0 and 1).

int oldBrightNess = Android.Provider.Settings.System.GetInt(ContentResolver,
Android.Provider.Settings.System.ScreenBrightness);

Does anybody have any bright (well... I need blacked out and bright) ideas
on how to solve this one?

Regards
Stephan



--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/Turning-display-on-and-off-tp5712611.html
Sent from the Mono for Android mailing list archive at Nabble.com.


More information about the Monodroid mailing list