I would like to know if it is possible to let the screen turn off (as setted in device parameters) but to prevent the phone to lock while my application is running in front.
So, when something happen in the app, I can turn on the screen and the user dont have to unlock his phone. (It is a driving application, so it would be dangerous to make the user unlock the phone while driving)
Thanks!
EDIT:
I dont want the screen to stay on : I want to be able to turn it on and when I do, that I dont have to unlock the screen.
Use this in your activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| +WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
I hope it will help. This will prevent your app to lock while your activity is visible.
There are many ways to do this.. One of the way is to set this flag in your activities oncreate.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
For the other ways to keep your screen on.. Link.
Related
My android app is able to run on the bakground and I'd like it to do so wenever the user stops interacting with the phone.
I the app is open and the user does nothing with it for x time, I expected Android to lock the screen (which is what i want).
However, the app simply keep th screen on. Why?
I do not use android:keepScreenOn="true" anywhere on the app.
Are you acquiring a WakeLock ?
If yes you should use PARTIAL_WAKE_LOCK instead FULL_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK the first lets the screen go off, the others don't
Well, turns out it was my fault, not the apps.
I had enabled 'Keep screen awake while charging', and since I had the phone connected to the computer, the screen never locked...
I'll leave this here in case someone else is in the same situation.
I'm writing an Android app that mostly communicates with the user via status bar notifications. However, I would like to not bother the user if s/he is not really directly interacting with their phone. For example, if the user is using the navigation app or watching a movie. I think that the commonality between all (or most) of these kind of apps is that they keep the screen on. I believe an app can keep the screen on by using a WakeLock or by specifying a keepScreenOn parameter on their activity, there might be other ways.
I wanted to know if, before I am about to show a notification, I can check if another application is keeping the screen on so I can avoid bothering the user. I'd like to cover all options. I can see that WakeLock has an isHeld() method, but will that detect the other method?
Thank you,
I think the best you can get is PowerManager.isScreenOn();
Acquire screen bright wakelock with ACQUIRE_CAUSES_WAKEUP flag. U have to acquire this wakelock bcoz it will force the screen to turn ON if its not. Even if the screen is already ON, one can not guarantee it will remain ON till ur application is running unless u acquire the wakelock. Dont forget to release the wakelock when u r done.
I think you can just post notifications on status bar regardless of state - applications requiring full user attention will typically disable display of status bar altogether -
so no harm will be done by your updates.
I need to lock the Android phone when the user leaves a defined WiFi area
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
I need to unlock the phone when user is back to the WiFi area
I guess list items 1 and 3 can be done programmatically.
Is it possible to do the 2nd item?
Locking can be done using this method: How to lock the screen of an android device
Unlocking look here: How to display Activity when the screen is locked?
For your problem 2, i see 2 solutions
a. If the user unlocks the screen, a message is fired: check at that moment if you are in the area and if not, instantly lock again
b. create your own locksreen with no possibility to unlock yourself
I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area
Fortunately, this is not supported, for obvious security reasons.
You are welcome to create your own home screen that offers different behavior when inside/outside a defined area and use that in lieu of trying to prevent a phone from being unlocked. However, the user is welcome to remove that home screen by booting their device into safe mode and uninstalling your app.
I had done similar thing in past but dont have the code right now so cant help in that respect. What I did is implement the app as Car Dock that will make the Home button override unless car-dock mode is dis-abled. I hope this will help, for code google it you definitely find resources
I guess this will help you out. This is just for Disabling the Lock Programmatically.Disable Screen Lock
private Window w;
public void onResume() {
w = this.getWindow();
w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
super.onResume();
tToast("onResume");
}
My customer want a screen-saver for android, I use the
KeyguardManager
Intent.ACTION_SCREEN_OFF
Ref: http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
When the Intent.ACTION_SCREEN_OFF received, my activity really started. but the screen is off, so I can not see nothing, What I really want is the sreen-saver UI will show on screen.
Is there a way to control the screen on/off programmtically?
You should see Coding for (Battery) Life Google IO presentation, slide 16 for keeping screen on
see if this helps
http://www.androidsnippets.com/stop-screen-from-dimming-by-enforcing-wake-lock
If I want to write a Screensaver or Lockscreen. Is there a way to prevent the home key from going back to the launcher?
Simple: when you enter the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
and when you exit the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);
Taking over the home key is an Android no-no.
The only screensaver in Android should be the screen going off. Why would anyone want to run down their battery instead of just pressing one button to turn the screen off and doing the same to turn it back on? It just doesn't make sense on a device with a very limited power supply to run a screensaver.
I'm not quite sure but from what I have read online, custom lock screens can only be done in custom firmware or rooted applications.