I've got an app that seems to prevent the screen from turning off when it's visible.
I am not holding any SCREEN_* wakelocks anywhere in the application.
I am holding PARTIAL_WAKE_LOCK for short periods of time (10-20ms). For a particular run I see this wakelock held once and then released, but the screen still stays on indefinitely.
For this test I have set the screen timeout to the shortest possible time (15 seconds) and have disabled keeping the screen on while charging.
If I switch away from my app to anything else, the screen goes off in 15 seconds.
I am not using any kind of XML in my layout resource (as this question suggests to keep the screen on)
I am also not calling getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); as a different answer to the same question suggests.
What other ways could my app be preventing the screen from turning off? This is certainly not the intended behavior!
Related
I am trying to program a bedside clock like the Moto 360's showing the time during the night while charging.
Therefore I have set up an "Always-On-App" with alarm manager according to https://developer.android.com/training/wearables/apps/always-on.html#BackwardCompatibility which works basically as intended (Android 7.1.1 Wearable Activity on a "Diesel On Full Guard").
However after several minutes lying still on the desk, the watch is leaving ambient mode (my preferred mode during night time) and switching its screen off.
I've already tried using a wake lock according to Android Wear: measuring sensors and preventing ambient mode / sleep but with no success. The processor may still be working, but the screen goes black after a while (very bothersome to debug as you always have to wait and can't reproduce on the emulator, which never switches off).
So how can I prevent the watch from leaving ambient mode onto the direction "off", or at least detect that state and switch it back on?
Your watch probably has ro.ambient.plugged_timeout_min set to some positive value (see the reddit post here). It's meant for protecting the OLED screen from burn in. If you run adb shell dumpsys alarm you can see a wake alarm for com.google.android.wearable.ambient with the action com.google.android.wearable.action.STOP_AMBIENT_DREAM that will turn the screen off/doze device after the timeout mentioned above.
My best guess is that to prevent it from going to ambient you'd need to either
Stop it from going into ambient entirely, i.e holding a SCREEN_DIM_WAKELOCK or similar, and using an entirely black background.
Periodically wake the screen up so that the timeout resets. This is probably suboptimal if it's meant as a night clock though.
I'm trying to make an android app that can disable the screen when not in use, but can be easily be accessed with out unlocking the phone. The simplest way would be to disable the lock screen I guess. I have tried the disableKeyguard / FLAG_DISMISS_KEYGUARD / FLAG_SHOW_WHEN_LOCKED, but they all appear to no longer be working. My current thinking is that I will need to keep the app from closing, and simply dim the screen, however, since the use case will have the app in use periodically over several hours, I am really looking to avoid this way of doing it.
Is there any way to create an app that can stay active, but sleep when not in use, without requiring an unlock?
Use FLAG_DISMISS_KEYGUARD with FLAG_SHOW_WHEN_LOCKED. If you need to keep the screen on, use FLAG_KEEP_SCREEN_ON. If you need the app to be running while screen is off, use a wakelock.
My friend dim portion is not going to work you because it will still glow in black room and drain battery.
Why don't you just set the application sleep time to 1 second. And on touching back the screen, it will set back to some maximum number for sleep time.
I'm making an app that uses the Proximity Sensor while a phone call is in progress. My main issue is that the device doesn't turn the screen off when I hold it up against my face (while talking on the phone). If anyone has a solution as to how to fix this, then my problem will be solved.
Right now though, I'm trying to manually switch the screen off to imitate the normal behavior of the phone app. I looked through a lot of other posts about this but most of them seem to have instructions on how to keep the screen turned ON. My case is the exact opposite... how do I programmatically set the device to turn it's screen off? I don't want it to lock itself or sleep (since the phone call will still be in progress), just turn the screen completely off.
Thanks!
I read all there is about wake locks and so on. But I want something different. I have three devices to test, and mainly one device sucks really hard. Its the Asus transformer. The main problem, it can't be charged over USB. This means, if I tell it to "stay enabled during debug" the battery is dead after a while.
Also I want to write a small script deploying my app to all three devices once I build (no problem), starting them (no problem), and then ENABLE THE SCREEN (no way till now).
If found this intent, was happy for 23.5 seconds, and then read this:
http://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_ON
Is there any way for me to enable the screen. The device is black, the screen is locked, my app starts (this works, seeing debug messages and hear startup sound), but i would have to manually unlock the screen.
I know, its not THAT bad, but when developing UIs I would have to do this like 100 times a day, and this is annyoing. The two little ones could stay on, but the big one (Transformer) would be empty after a while. I just had a thought, maybe I can tell the Transformer only to dim after a while, and to "undim" on startup. Would increase lifetime tenfold.
But still, if anyone knows a way to turn the screen on, that would be fantastic!
Chris
[UPDATE]
Ok, what you can do is reduce the screen brightness after some time, by using this:
WindowManager.LayoutParams WMLP = getWindow().getAttributes();
WMLP.screenBrightness = 0.01F;
getWindow().setAttributes(WMLP);
Dont use 0 as a value (at least not until this question is answered), because the screen will switch off, and you will never get in on again. At least without using your thumb and pressing a button, sooo oldschool...
I would like to be able to keep the android screen from locking in an application. This is not a marketplace application. It is installed on a dedicated tablet.
The only solution I've found is using the Power Manager and using a WakeLock. This way I can keep the screen from locking, but it also keeps the screen from dimming thus wasting battery.
What I would like is for the screen to dim and turn off the way it always does, but that it is able to wake up when touched and not require the user to press the power button and unlock.
Is this even possible? How would you do something like this?
The only solution I've found is using the Power Manager and using a WakeLock. This way I can keep the screen from locking, but it also keeps the screen from dimming thus wasting battery.
You are perhaps using the wrong WakeLock. Please read the PowerManager documentation and try a different WakeLock. There are WakeLock versions that support anything from the screen being off, to the screen being dim, to the screen being normal brightness.
Is this even possible?
If the screen is off, it will not respond to touch events.