I am currently making an Android application in which I need the phone to not lock, so as to avoid the activity losing focus.
I have done a bit of research and found numerous ways to do it including the use of:
Keyguard Manager
Power Manager
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
android:keepScreenOn="true"
I tried using the android:keepScreenOn="true" in my Android manifest, but it seemed to have no effect on the application. I am hesitant to using power manager as every post about it is filled with numerous warnings.
In closing, what is the best way to prevent the Android phone from locking and losing focus of the application? The screen itself may dim or turn off, so long as the application remains in focus and the phone doesn't lock.
What you want can easily achieved by using the PowerManager with a Screen Dim Wake Lock.
Also, IIRC, keepScreenOn is supposed to be added to a widget in an XML file, not in the manifest, if you do decide to use that in the end.
Related
I want to prevent remote screen recording of my app using third party apps like Anydesk, Quicksuppport, Teamviewer etc.
I have used below flag for activity :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
but the above flag doesn't work for all devices.
Any other work around for preventing remote screen recording?
The apps you mentioned are operating with either permission of CAPTURE_VIDEO_OUTPUT or CAPTURE_SECURE_VIDEO_OUTPUT. Unfortunately, if they own CAPTURE_SECURE_VIDEO_OUTPUT, then setting the FLAG_SECURE on your window has no effect from their viewpoint.
Sadly, I don't think there is a better (or more effective) way to achieve the desired behavior.
If you make your app a device administrator, then (on certain api levels) you will have the ability to disable screen capturing on the entire device, but setting this up is a lot of hassle, and it's probably not what you want to do in the first place.
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.
A few users have been asking me Android lock screen widgets for my app - I believe they want a widget that stays on their lock screens and allows them to interact with the app.
I haven't been able to find any official documentation for this - the only thing I found was apps that will take home screen widgets and put them on the lock screen for you.
Any clues on where I learn more about building true lock-screen widgets?
Lock screen interaction is difficult. Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD). FLAG_SHOW_WHEN_LOCKED works pretty consistently in that it will show on top of the lock screen even when security is enabled (the security isn't bypassed, you can't switch to another non-FLAG_SHOW_WHEN_LOCKED window).
If you're just doing something temporary, like while music is playing or similar, you'll probably mostly be okay. If you're trying to create a custom lock screen then there's a lot of unusual interactions on all the different android platforms. ("Help! I can't turn off my alarm without rebooting my HTC phone").
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
FLAG_SHOW_WHEN_LOCKED
Window flag: special flag to let windows be shown when the screen is
locked.
FLAG_DISMISS_KEYGUARD
Window flag:
when set the window will cause the keyguard to be
dismissed, only if it is not a secure
lock keyguard. Because such a keyguard
is not needed for security, it will
never re-appear if the user navigates
to another window (in contrast to
FLAG_SHOW_WHEN_LOCKED, which will only
temporarily hide both secure and
non-secure keyguards but ensure they
reappear when the user moves to
another UI that doesn't hide them). If
the keyguard is currently active and
is secure (requires an unlock pattern)
than the user will still need to
confirm it before seeing this window,
unless FLAG_SHOW_WHEN_LOCKED has also
been set.
Constant Value: 4194304 (0x00400000)
Official Lock screen widget document is here
I had to implement a lock screen widget for my project. In the process, I accumulated a couple of resources.
If you have an app that you want to put on the lock screen, first make it an appwidget. You can use the AppWidget class to do this.
Now, use the AppWidgetHost class from the Android API to make your lock screen a host for the widgets. I don't know how to do this part, but there are some existing implementations like mylockandroid (links below).
Resources
http://code.google.com/p/mylockforandroid/
(NB This code is for older versions of Android. Android 4.2 and up has built in lockscreen widget support)
http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html
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.
A few users have been asking me Android lock screen widgets for my app - I believe they want a widget that stays on their lock screens and allows them to interact with the app.
I haven't been able to find any official documentation for this - the only thing I found was apps that will take home screen widgets and put them on the lock screen for you.
Any clues on where I learn more about building true lock-screen widgets?
Lock screen interaction is difficult. Android allows basic operations with two window flags (FLAG_SHOW_WHEN_LOCKED and FLAG_DISMISS_KEYGUARD). FLAG_SHOW_WHEN_LOCKED works pretty consistently in that it will show on top of the lock screen even when security is enabled (the security isn't bypassed, you can't switch to another non-FLAG_SHOW_WHEN_LOCKED window).
If you're just doing something temporary, like while music is playing or similar, you'll probably mostly be okay. If you're trying to create a custom lock screen then there's a lot of unusual interactions on all the different android platforms. ("Help! I can't turn off my alarm without rebooting my HTC phone").
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html
FLAG_SHOW_WHEN_LOCKED
Window flag: special flag to let windows be shown when the screen is
locked.
FLAG_DISMISS_KEYGUARD
Window flag:
when set the window will cause the keyguard to be
dismissed, only if it is not a secure
lock keyguard. Because such a keyguard
is not needed for security, it will
never re-appear if the user navigates
to another window (in contrast to
FLAG_SHOW_WHEN_LOCKED, which will only
temporarily hide both secure and
non-secure keyguards but ensure they
reappear when the user moves to
another UI that doesn't hide them). If
the keyguard is currently active and
is secure (requires an unlock pattern)
than the user will still need to
confirm it before seeing this window,
unless FLAG_SHOW_WHEN_LOCKED has also
been set.
Constant Value: 4194304 (0x00400000)
Official Lock screen widget document is here
I had to implement a lock screen widget for my project. In the process, I accumulated a couple of resources.
If you have an app that you want to put on the lock screen, first make it an appwidget. You can use the AppWidget class to do this.
Now, use the AppWidgetHost class from the Android API to make your lock screen a host for the widgets. I don't know how to do this part, but there are some existing implementations like mylockandroid (links below).
Resources
http://code.google.com/p/mylockforandroid/
(NB This code is for older versions of Android. Android 4.2 and up has built in lockscreen widget support)
http://mylockandroid.blogspot.com/2010/03/widget-lockscreen-beta-11-r2.html