锁定Android手机手机、Android

2023-09-06 05:50:24 作者:别闹我女神在@

可能重复:   锁定Android设备编程

我希望能够当我运行一个方法来锁定Android手机用密码。 有没有人有一个参考或样品code给我参考。谢谢

I want to be able to lock the Android phone with a password when I run a method. Does anyone have a reference or sample code for me to refer. Thanks

修改 我曾试过用

KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); 
lock.reenableKeyguard();

如说通过下面的答案,但我仍然试图得到它补充说,我已经在我的服务器端具体输入数据库密码,所以要解开他的电话的唯一途径是进入密码我设置

as said by the answer below, but I'm still trying to get it to add a password that I have specifically entered into the database at my server side, so the only way to unlock his phone is to enter the password that i set

修改

的http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html

一直在努力工作吧^

修改

我已经看到了

device_admin_sample.xml

与内容

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
    <limit-password />
    <watch-login />
    <reset-password />
    <force-lock />
    <wipe-data />
  </uses-policies>
</device-admin>

但是,在我把这个xml文件的..它似乎有一个错误的地方,我把

But where do I put this xml file at.. it seems to have an error wherever i put

修改

现在,我已经实现一半,并在看到下面的评论,我不能用密码锁定手机把这个搁置。 但看到API文档,有一个功能,使用新密码重设密码。

Now, I have implemented it halfway and put this on hold upon seeing the comment below that I cannot lock the phone with a password. But seeing the API documentation, there's a function to reset password with a new password.

resetPassword(String password, int flags)

那么是什么呢?我可以在手机上的密码锁?或者是锁定手机,直到服务器赋予了新的密码输入的想法,不能做什么?

So what is it? Can I implement password lock on the phone? or is the idea of locking the phone until a new password given by the server is entered, unable to be done?

推荐答案

您的应用程序无法阻止$ P $任何pssing home键和走出你的应用程序。 这prevents恶意软件或坏codeD应用程序来锁定手机的时候,你需要取出电池走出crapware的。

Your app cannot stop anyone from pressing the home button and getting out of your app. This prevents malware or bad coded app to lock the phone to the point you need to remove the battery to get out of the crapware.

您可以通过编程锁定与通常的屏幕更衣室屏幕,但:

You can programmatically lock the screen with the usual screen locker though :

KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); 
KeyguardLock lock = mgr.newKeyguardLock(KEYGUARD_SERVICE); 
lock.reenableKeyguard();

这将要求禁用键盘锁权限在manifest文件。

This will require the "Disable Keyguard" permission in your manifest file.

OP细化后编辑:

看看这个示例演示了如何使用设备管理经理:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html

Take a look at this sample that shows you how to use the device admin manager : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html