Unlock a screen in android using disableKeyguard - android

In my application I am using disableKeyguard and reenableKeyguard to Unlock and lock a screen. my application is working fine. But problem is when user unexpectedly unlocked a screen by dragging keygaurd (without using my application), the screen does't lock again with my application.
How to solve this problem?
Thanks in advace

Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Handle returned by newKeyguardLock(String) that allows you to disable / reenable the keyguard.

Related

How can Next lock screen (Microsoft) bypass the system lock screen with fingerprint?

I'm currently developing a lock screen application. I have used Next lock screen and realised that it can bypass the system lock screen if fingerprint is enabled. I have done several reseach to find out the way. Unfortunately, I could not do that. But I have some conclusions based on my research:
Next lock screen can ONLY bypass the system lock screen if at least 1 fingerprint is set.
Next lock screen can ONLY bypass the system lock screen PROPERLY on android 7.1.1 and below. It CANNOT do that on android 8.0. If you have a chance, please use it and you can understand what I am trying to say here.
There are differences between android 7.0 and 8.0.
On Android 7.0, when an activity shows up ON TOP OF the system lock screen, the keyguard behind stops reading fingerprint. Somehow, Next lock screen enables the keyguard to continue reading the fingerprint but I don't know. I'm trying to do this.
On Android 8.0, with the same case, the keyguard behind CAN STILL READ the fingerprint. Therefore, if the fingerprint is correct, the phone is unlocked and I can catch the event of "USER_PRESENT" to dismiss my lock screen. However, Next lock screen fails to function properly.
And now, my question is how I can make the keyguard to continue reading the fingerprint while my custom lock activity is showing on top?
This is what I want: My custom lock screen will show up on top of the system lock screen. The system lock screen can have any type of security methods (password or pattern). If and only if the user enables fingerprint unlock in the system, they can use fingerprint on my custom lock screen to unlock the device (the system lock screen is unlocked at the same time my lock screen disappears)
Thank you very much.
They do not run Activity as their lockscreen but they just draw their view into WindowManager and somehow listens for lockscreen unlock and then they hides their UI. Check this - Android Lockscreen with FingerPrint support

How to set an app as default app in android programmatically

i'm working on a lock screen app for android , i want to make my app as the default lock screen app for mobile instead of the current lock screen .. how is that done programmatically ?
any help ?
You cannot replace your lockscreen app with default lockscreen. What you can do is, you can make your app work as a lockscreen. User will have to disable all default locking mechanism (pin, gesture etc.). And your app will be triggered every time user switches on the screen. That's how other lockscreen apps (like Go Locker etc.) work.

Can disableKeyguard() method dismiss secure lock also?

I want to ask about the disableKeyguard() method in KeyguardManager.KeyguardLock class
The documentation says :
Disable the keyguard from showing. If the keyguard is currently
showing, hide it. The keyguard will be prevented from showing again
until reenableKeyguard() is called. Note: This call has no effect
while any DevicePolicyManager is enabled that requires a password.
However this class is deprecated since API level 13
Alternate method is to use flags from Window manager
FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED
Now these flags work only if lock mode is Swipe
In case of secure lock like PIN or password it can mostly bring one window above
lock screen, but as soon as user moves to another window, the lock reappears.
I want to ask that is the same true for disableKeyGuard() too.
Is it only effective in case of Swipe but not for secure locks like PIN / Password / Face detection etc.

Android Keyguard Lock

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.

Using disableKeyguard and reenableKeyguard to lock and unlock

In my application I am using disableKeyguard and reenableKeyguard to lock and unlock a screen with proximity and accelerometer sensors respectively. My application working with some bugs. If user unlocks a screen by dragging (without using my app) then my application will not lock !. How to prevent this issue? How to fix this bug? plz help me.
Is there any other way to lock and unlock ?
thanks in advance.
reenableKeyguard
void reenableKeyguard() Reenable the keyguard. The keyguard will
reappear if the previous call to disableKeyguard() caused it to be
hidden. A good place to call this is from onPause() Note: This call
has no effect while any DevicePolicyManager is enabled that requires a
password.
This method requires the caller to hold the permission
DISABLE_KEYGUARD.
Your app has to be the one to call disableKeyguard() first, else you cannot lock it using reenableKeyguard()
Source: https://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html

Categories

Resources