I'm using getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); to turn on the screen programmatically. Is there a WindowManager feature that turns off the screen progrmamatically? I want the user to press a button and then exit out of the activity and turn off the screen.
As far as i know, you cant really turn the screen off (in the traditional sense). You can, however, dim it as much as possible (like the Phone app does for instance, when you move your phone close to your face).
Check THIS answer for the solution. Just modify the code so it doesn't use the onSensorChanged listener.
Related
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.
Hi I am an Android newbie, I want to create an app which stays displayed even if the power button is pressed, I used,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
but I had to press power button again to display the app, someone suggested me to use,
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
but it doesn't seem to work. Is there any work around ?
You can't prevent hardware keys overriding. Power button works on hardware level. Ur app will be unable to turn screen on after it was turned off by hardware.
We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
What's the best approach (battery performance) to this?
Using a Partial Wake Lock (will the screen react?)
Disable the screen in some way, but keep everything (including touch response) working?
Other?
Any suggestions on this?
Gabriel,
Since this isn't possible by completely turning the screen off, you may want to just want to use a wake lock and dim the screen to its lowest setting as your 'timeout'. This way you can still accept screen touch events and 'wake' it from this state and bring it back to its previous brightness.
We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
This is impossible except perhaps via custom firmware. If the screen is off, it will not respond to touch events.
Another thing you could do is use an app to turn screen off like ScreenStandby since it works in the background and can start on boot as well.
Out of curiosity, how can we go about contacting someone to help in creating a custom firmware like you did Gabriel?
Could someone please show me a sample code snippet where you use two buttons; one to turn off and one to turn on the screen. I cant get it to work. Thanks!
I don't understand your question properly. A wake lock is set in your application so that the device screen does not turn off after a particular span of time. how ever you are advised to use this FLAG_KEEP_SCREEN_ON flag and is the best way
Force Screen On
Erm, when the screen is off, how are you hoping to display a button? Unless you mean hardware buttons, in which case I think only the power button can turn the screen back on.
I'm working on my first android app. So far I have an activity that reacts to clicks on the hardware volume controls. That's was easy to do, but I'm wondering if there is a way to make it so the app responds to these events from the hardware buttons even while the phone is locked?
I'm really looking for a confirmation of whether or not this can be done. If someone could confirm and give me the general idea of how to do it that would be awesome.
I have not done exactly this but I believe that if you put
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
in your Activity onCreate() you will be able to do what you want even if the screen is locked.