[英]Android pattern lock/unlock screen programmatically
Part of my app is to lock screen using a certain pattern the user chooses and unlocks it with the same pattern. 我的应用程序的一部分是使用用户选择的某种模式锁定屏幕并使用相同的模式解锁它。 I wish to use the same android default Pattern lock screen. 我希望使用相同的Android默认模式锁屏。 I want the user to be able to set up multiple patterns and unlock the screen with these patterns. 我希望用户能够设置多个模式并使用这些模式解锁屏幕。
Any ways I can do that? 我能做到的任何方式吗? Is there some intent or class I can call to do that? 我可以打电话来做那些意图或课程吗? Or do I have to develop such mechanisim from scratch? 或者我是否必须从头开发这样的机制? I have no idea where to start with 我不知道从哪里开始
Heeeelp! Heeeelp! Thank you 谢谢
Lets try below code really helpful 让我们尝试下面的代码真有帮助
Intent settingIntent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivityForResult(settingIntent, 0);
many thanks 非常感谢
You can call lockNow method by DevicePolicyManager
. 您可以通过DevicePolicyManager
调用lockNow方法。
public class MobileDeviceAdminReceiver extends DeviceAdminReceiver {
}
ComponentName deviceAdminReceiver = new ComponentName(this, MobileDeviceAdminReceiver.class); // Register BroadcastReceiver in manifest;
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);// admin permission intent
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,deviceAdminReceiver);
Or create your custom lock screen that monitoring top activity and block it. 或者创建自定义锁定屏幕,监视顶级活动并阻止它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.