Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use screen lock in my app

Tags:

Is it possible to use the default security settings, which user has set to the phone, as a locking or login mechanism for my app too? I mean like when we reset the phone, it asks for phone password or pattern.

Is it possible the same way that I can use the default android password or pattern set by user to login to my app?

My goal is to bypass the developing effort and use some standard way of authentication without making user to remember another new password.

NOTE: I'm aware that I can lock the screen programmatically. But instead, I want to use the lock as a verification before performing any critical operation. (Just like how Settings ask for the password before resetting the the phone.)

like image 880
Mangesh Avatar asked Apr 05 '15 10:04

Mangesh


People also ask

Can you put a time Lock on an app?

Open your phone's Settings app. Tap Digital Wellbeing & parental controls. Tap the chart. Next to the app you want to limit, tap Set timer .


1 Answers

Actually, there is an API to exactly that using the KeyguardManager.

First get a the Keyguard SystemService:

KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE); 

And then request an authentication intent using:

Intent i = km.createConfirmDeviceCredentialIntent(title,description); 

start this intent using startActivityForResult(Intent, int) and check for RESULT_OK if the user successfully completes the challenge.

This is for API level 21. Previous versions might work with KeyguardLock.

like image 63
agi Avatar answered Sep 23 '22 14:09

agi