在我的应用中使用屏幕锁定 [英] Use screen lock in my app

查看:79
本文介绍了在我的应用中使用屏幕锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将默认的安全设置(该用户已将其设置为手机)用作我的应用程序的锁定或登录机制?我的意思是,就像我们重置手机一样,它会要求输入手机密码或密码.

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.

是否可以使用用户设置的默认android密码或模式登录我的应用程序的相同方法?

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.)

推荐答案

实际上,有一个API可以使用

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

首先获得Keyguard SystemService:

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);

使用 startActivityForResult(Intent,int)启动此意图,并检查 RESULT_OK ,如果用户成功完成了挑战.

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

这是针对API级别21的.早期版本可能与 KeyguardLock .

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

这篇关于在我的应用中使用屏幕锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆