Open nolanlawson opened 11 years ago
After investigating, I'm not sure this is actually possible. I can't find in the API where I can manually dim the screen without shutting off the Activity entirely.
Don't you just need to set the activity's LayoutParams.screenBrightness
?
There's a PhoneGap plugin I've used that does just that.
Yeah, but it's complicated because apparently the API has been deprecated/changed since 4.0. Anyone interested is free to take a crack at the code, though!
The docs don't seem to indicate that it was deprecated. (Compare to the memoryType
property a few items above screenBrightness
– it has a big orange deprecation warning.)
I don't have any insight into Android development, but I think you don't need to dim the screen programatically, just let Android do it itself. Both Unsleep [1] and Keep screen on! [2] are able to do that on Android 4.4. The latter has an option of SCREEN_DIM_WAKE_LOCK
which does exactly the right thing - prevents the screen from turning off, but after a default timeout (configured in your settings), the brightness is reduced to a very low value.
[1] https://play.google.com/store/apps/details?id=com.nealc.unsleep [2] https://play.google.com/store/apps/details?id=si.formias.keepscreenon
OK, so maybe the fix is to use the new 4.4 option in post-4.4?
I'm happy with deprecating pre-4.4 and shipping only a minSdk=19 APK from now on.
I have no idea whether the stuff I mentioned is new in 4.4. I just know it works on 4.4, that's the only version I can test :-)
Keep Screen On! supports 2.0 and higher and references http://developer.android.com/reference/android/os/PowerManager.html in its description.
Unsleep supports 2.3.3 and higher and there's no information how it does it.
http://developer.android.com/reference/android/os/PowerManager.html#SCREEN_DIM_WAKE_LOCK says it's deprecated and suggests http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON , but that flag doesn't seem to support dimming (the documentation says keep the device's screen turned on and bright
).
Maybe the deprecated option would be good enough for the time being?
Currently KeepScore can destroy a phone's battery, because having the screen on eats a ton of power. During a two-hour game of Rummy, the battery on my Galaxy Nexus running Android 4.2 dropped almost 20%.
Turning the screen off entirely is not an option, because we don't want to make users unlock their lockscreen over and over again. (Especially because your friends probably don't know your password.) But dimming the screen after a certain timeout might offer some battery savings.