FLAG_KEEP_SCREEN_ON does not work during keygaurd lock - android

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.

Related

How to lock/unlock phone from Service in android?

I want to lock/unlock android using a service. I have checked other questions but none works. Some require to have my app in foreground and some I don't understand well enough. I want to show the lock screen if the device is password locked else home screen.
Just Turning screen on and off only will also work. Anyone know how to do it?
Edit 1:
I have tried things and managed to turn on(WakeLock) and off(DevicePolicyManager) screen. However, turning off screen does not lock phone only turns off the display. I use locknow(). This is acceptable but if possible can anyone tell how to lock phone?
Edit 2:
I can not lock my phone even by using physical lock button. It just turns off the screen.

Is it possible turn off the screen with WindowManager?

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.

Activate Android with touch instead of power button

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?

Android wakelock question

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.

Is there a way to make an android app respond to hardware buttons while phone locked?

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.

Categories

Resources