I'm trying to develop a very simple app that displays like a slideshow of images which Im sure ill be able to figure out (if anyone has any advice would be much appreciated) but what im wondering is there any way I can stop the device from going to sleep if its left cycling through these images?
using
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
will make the screen always on which will disable the lock. Remove it by using
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Add android:keepScreenOn="true" to some widget in your activity's layout XML file. While the activity is in the foreground, the device will not fall asleep.
You would use a wake lock.
http://developer.android.com/reference/android/os/PowerManager.WakeLock.html
Related
I am developing an app that locks the screen for some time, just like parental control apps do when the screen time runs out. However, I do not really know how they work. I suppose they don't use lockNow because there is that message that shows up telling you that the time has run out. I also don't think they use overlays, because the phone is supposed to detect the use of overlays. So does anybody know what kind of function is used? Also for my app I want to add a button that ends the screen lock, so I am looking for a suitable way to achieve that.
I've made an app that has the unlock formatting that I want, but I don't know how to make it so that I can select that as the device security screen lock, or even if it is possible.
At the minute I have it so that when the phone is unlocked, the unlock app starts - however there is always a slight delay, and the app toolbar is visible at the top for a short period of time.
I've looked around for a very long time and not been able to find any resources on this other than with what I've already done, any help would be greatly appreciated.
(If it helps, the device I'm developing for is using Android 6.0.1)
Are you talking about a custom screen lock?
This may help.
https://github.com/Joisar/LockScreenApp
Okay in the LockScreenApp Activity class
every method call in the onAttachedWindow method needs to be moved to the onCreate method
I'm developing an application and the last touch I need to put on it is preventing the screen to lock when the device goes into standby (screen off). The exact behavior as Google Navigation.
I'm wondering what, programatically I will have to use to keep this feature enable the entire time while using the app?
writing the following code to your xml file will prevent the screen from locking
android:keepScreenOn="true"
In the onCreate of your activity after the setContentView use this:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Not tried it myself.
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.