锁定安卓手机[英] Lock an Android Phone

本文是小编为大家收集整理的关于锁定安卓手机的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

可能的副本:
以编程方式锁定Android设备

我希望在运行方法时能够将Android手机锁定密码. 有没有人有一个引用或示例代码给我参考.谢谢

编辑 我尝试过使用

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

如下面的答案所说,但我仍然试图让它添加我在服务器端专门输入数据库的密码,因此解锁他的手机的唯一方法是输入密码我设置了

编辑

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文件放在......无论我放置

,它似乎都有一个错误

编辑

现在,我已经实现了它,并在看下面的评论时将此置于我不能用密码锁定手机. 但看到API文档,有一个功能要重置密码的功能.

resetPassword(String password, int flags)

所以它是什么?我可以在手机上实施密码锁吗?或者是锁定手机的想法,直到输入服务器给出的新密码,无法完成?

推荐答案

您的应用程序无法阻止任何人按下主页按钮并退出您的应用程序. 这可以防止恶意软件或错误的编码应用程序将手机锁定到您需要卸下电池的点以离开掷骰子.

您可以使用通常的屏幕储物柜以编程方式锁定屏幕:

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

这将需要清单文件中的"禁用keyguard"权限.

编辑op细化后:

看看这个样本,向您展示如何使用Device Admin Manager: http://developer.android.com/resources/samples/apidemos/src/com/example/android/apis/app/deviceadminsample.html

本文地址:https://www.itbaoku.cn/post/102448.html

问题描述

Possible Duplicate:
Lock the android device programatically

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

EDIT I have tried using

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

EDIT

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

been trying to work on it ^

EDIT

I have seen that

device_admin_sample.xml

with the contents

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

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

EDIT

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?

推荐答案

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

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

EDIT after OP refinement :

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