In Android, you can go to system settings and enable screen locking whereby you can require a password, PIN, or some other means of unlocking the screen. This is typically used if you put your device into standby mode or it goes into standby mode after the screen dims out.
What I would like to do is to re-use this screen locking within my app but to prevent access to a particular activity. I would have a button that when pressed brings up the screen lock activity where the user must enter their PIN. If they enter it correctly, I then let them have access to the activity, otherwise they cannot use it.
Is it possible to re-use the screen locking activity in this scenario? If so, what API do I need? Would be nice if it worked on Android 2.3
EDIT:
Some of you are assuming that my app REQUIRES a PIN or password to operate. That is not the case. Users who want to protect certain data in my app can require it to have a PIN or password in order to view it. But why write my own password/PIN activity or dialog when the system already has one.
That kind of security is only available to inbuilt system components, like the settings app. Third party apps cannot request for the password dialog to be shown, and only continue working if the user enters the correct code.
Additionally, a decent amount of users simply do not have a pass code on their device.
You could look at KeyguardManager and KeyguardManager.KeyguardLock. There seems to be a change in how this functionality works starting in API level 13, but I'm not familiar with the topic in general, so you'll have to investigate that if you plan to go this route.
You are probably better off implementing something self contained in your app. It's very easy to cover the screen (perhaps with another Activity) or to hide UI elements programmatically and show an alternate UI with a password input field or something.
You can use the Screen locking feature from Android 2.2 itself.So, it will work in 2.3 easily.The method to use this feature can be done in basically two ways.
1st one is.
There are two way you can lock the screen:
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(int amountOfTime);
The second one is
PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,Your Tag");
wl.acquire();
wl.release();
The permission is also needed.that is
<uses-permission android:name="android.permission.WAKE_LOCK" />
Related
I'm trying to create a new lock screen and I'm aware that if I use the FLAG_DISMISS_KEYGUARD for use with non-secured lock screens, I can present multiple functions and don't have any restrictions to intent access.
However, I've been having a very difficult time identifying what limitations are implemented if the user had a secure (password, pin, pattern, etc) keyguard active and I use the FLAG_SHOW_WHEN_LOCKED.
For example, if my activity is visible over the keyguard and the user wanted to change the background of the activity to a picture they took, they cannot access the gallery to select the photo if the phone is locked.
I couldn't find anything in the Android SDK documentation or on here (or anywhere for that matter) that could answer what other functions are disabled. Any and all help is greatly appreciated!
Thanks!
Is it possible to create an app on iphone and android that is accessible before the authentication screen, just like the "emergency dialler".
I searched on google but I cant seem to find relevant information.
On Android perhaps, depends on what you want exactly. You can make an app that appears above the keyguard by specifying FLAG_SHOW_WHEN_LOCKED. You can make it turn on the display with a wakelock or the flag FLAG_KEEP_SCREEN_ON. You can make it dismiss the keyguard with FLAG_DISMISS_KEYGUARD . But some of these will only work with a non-secure keyguard (one that doesn't require a password).
I am working on an application that will replace the default lock screen (swipe to unlock) for android devices. I have successfully done this by disabling the keyguard manager and showing my activity using the broadcast receiver for screen OFF and screen ON intent. Now, the problem is when I set the default screen lock again for any reason then my application would not disable the keyguard unless I force close it and launch it again.
km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
if( km.inKeyguardRestrictedInputMode()) {
//it is locked
km = (KeyguardManager) getApplicationContext().getSystemService(KEYGUARD_SERVICE);
kl=km.newKeyguardLock("com.example.helloworld.MainActivity");
kl.disableKeyguard();
} else {
Intent i = getIntent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);
}
You cannot replace the lock screen with a user application. Anything you do is a hack and may or may not work on some device, and will likely break with new releases. You can create something that looks like a screen lock, but it won't work like one. Additionally, in recent versions of Android (post-ICS), unlocking the screen does extra things like unlocking the credential storage, which your app cannot possibly do (since it doesn't have system permissions).
If you really want to replace the screen lock, you need to build your own Android ROM, modifying/replacing the stock one.
The accepted answer may be out of date.
It's now possible to use Device Admin to create and remove device passwords.
An application can be placed above the current lock screen using FLAG_SHOW_WHEN_LOCKED (complete explanation in another answer)
The keyguard can be dismissed using FLAG_DISMISS_KEYGUARD
As a result, it's theoretically possible to secure the actual lock screen using an app-generated password (providing real security), float a custom lock screen above the android lock screen, and -- when a proper password is provided -- unlock and dismiss the real lock screen. Finally, you would use a receiver to restore or clear the password on relevant events like SCREEN_OFF or SCREEN_ON -- the latter could automatically clear the password if a timeout was not yet reached.
FWIW, I don't recommend this approach since a crash or uninstall would leave a user with a device locked by a password they do not know.
I have a Service that keeps the display on at a dim level at certain times, and it uses a 'dim' WakeLock to accomplish this. It works well... except that the screen never locks. That is, while the dim WL is held, the lock screen never appears requiring the user to swipe and authenticate.
Note that I'm developing on a platform that may have vendor changes to the low-level Android Java framework code, so this might not be standard Android behavior. But also, I have access to the framework code and can change it, if necessary. I just can't figure out where this policy is enforced in the code.
When the device is on external power, we want to keep the screen contents visible - but we still want it to lock.
The only way I can think of to do that is for you to maintain your own timer for when to trigger the lock, then to use DevicePolicyManager and lockNow() to lock the device at that point. This requires extra permissions and extra setup work (enabling your app as a device manager).
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.