Android应用程序调用系统解锁页面
16lz
2021-01-23
Android应用程序调用系统解锁页面
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);/** *判断设备有没有设置解锁密码 */if (!mKeyguardManager.isKeyguardSecure()) { // Show a message that the user hasn't set up a lock screen. Toast.makeText(this,"Secure lock screen hasn't set up.\n" + "Go to 'Settings -> Security -> Screenlock' to set up a lock screen", Toast.LENGTH_LONG).show(); purchaseButton.setEnabled(false); return;} /** *跳转到系统解锁页面 */private void showAuthenticationScreen() { // Create the Confirm Credentials screen. You can customize the title and description. Or // we will provide a generic one for you if you leave it null Intent intent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null); if (intent != null) { startActivityForResult(intent, REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS); }} /** *接收系统解锁是否成功 */@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) { // Challenge completed, proceed with using cipher if (resultCode == RESULT_OK) { if (tryEncrypt()) { showPurchaseConfirmation(); } } else { // The user canceled or didn’t complete the lock screen // operation. Go to error/cancellation flow. } }}
注意事项
- 跳转系统解锁页面只能在5.0以上的设备使用,5.0以下的不支持
- 如果不对设备进行设置密码判断,intent就会返回一个null, 一定要对null值进行判断
参考文档
日本的博客链接
谷歌的官网demo
更多相关文章
- android 调用系统应用
- android实现调用系统音乐播放器
- Android系统设置选项的包名
- Android 隐藏系统状态栏和标题栏
- 关于屏幕解锁的实例
- 指定浏览器访问指定页面(支持UC、Opera、QQ、Dolphin、Skyfire、
- Android系统权限和root权限
- 仿照利用android系统源码资源文件,修改SeekBar颜色 前景与背景
- Android系统自带主题的使用及自定义主题