简体   繁体   English

如何通过代码远程解锁Android手机

[英]How to unlock android phone through code remotely

I have written an application that locks android phone remotely.我写了一个远程锁定安卓手机的应用程序。 That is when a special code is sent from server then application locks the phone based on the special code.也就是说,当从服务器发送特殊代码时,应用程序会根据特殊代码锁定手机。 This is the code I am using.这是我正在使用的代码。

if (!mDPM.isAdminActive(mDeviceAdminSample)) {
        // try to become active – must happen here in this activity, to get result
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mDeviceAdminSample);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"Admin is added to do security operation.");
        startActivityForResult(intent, 0);
        } else {
        // Already is a device administrator, can do security operations now.
        mDPM.lockNow();
        }

The above code is working and it's locking the phone.上面的代码正在工作,它正在锁定电话。

I am able to unlock the phone by entering password from soft keypad.我可以通过从软键盘输入密码来解锁手机。 Is there any way to unlock it through code?有什么办法可以通过密码解锁吗?

My question is how to unlock the phone through code.(This unlocking should be done remotely in the manner I explained for locking)我的问题是如何通过密码解锁手机。(这种解锁应该按照我解释的锁定方式远程完成)

I believe you cannot override the built-in screen-lock unless you make your own device like Samsung and HTC do.我相信除非您像三星和 HTC 那样制作自己的设备,否则您无法覆盖内置屏幕锁定。 However, by having your customers use your own screen-lock-like app you probably can achieve what you are trying to do.但是,通过让您的客户使用您自己的类似屏幕锁定的应用程序,您可能可以实现您想要做的事情。

I do not think your remote unlock goal is achievable.我认为您的远程解锁目标无法实现。

The way Android is set up, is that many apps may have Device Administrator privilege, and any Device Administrator can issue a lock command, but the unlock has to come from the user. Android 的设置方式是,许多应用程序可能具有设备管理员权限,任何设备管理员都可以发出锁定命令,但解锁必须来自用户。

I can suggest one thing you to simplify this: Your app could try to remove the key lock password, and then the user can use the device without a code simply by sliding a finger on the screen.我可以建议你做一件事来简化这个:你的应用程序可以尝试删除键锁密码,然后用户只需在屏幕上滑动手指就可以使用设备而无需密码。

Now there is a snag in what I suggested, if your app is not the only device administrator.如果您的应用程序不是唯一的设备管理员,那么我的建议会出现问题。 In that case, some other administrator app could set a minimum password length (or some other password restriction) which would prevent your app from clearing the screen lock password.在这种情况下,其他一些管理员应用程序可以设置最小密码长度(或其他一些密码限制),这会阻止您的应用程序清除屏幕锁定密码。

If your goal is to help a user that forgot his/her screen lock password, then your server could invent a new password, inform the user what the new password is, and also send the new password to your app and your app could apply the password.如果您的目标是帮助忘记屏幕锁定密码的用户,那么您的服务器可以发明一个新密码,通知用户新密码是什么,并将新密码发送到您的应用程序,您的应用程序可以应用密码。 The user can then unlock the phone.然后用户可以解锁手机。 Do not worry, it is not as complicated as it sounds.别担心,它并不像听起来那么复杂。

Sorry to write that - There is no way to unlock phone from code.很抱歉这样写 - 无法通过代码解锁手机。 If you find any way to do that - no warranty to work.如果您找到任何方法来做到这一点 - 没有工作保证。 So there is no way to remote unlock, writing custom lock screens, etc.所以没有办法远程解锁,写自定义锁屏等。

You need to use mDPM.resetPassword("", 0)您需要使用 mDPM.resetPassword("", 0)

http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String , int) http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String , int)

When set password string as "", current password is replaced with empty values & screen lock disappears.将密码字符串设置为“”时,当前密码将替换为空值且屏幕锁定消失。

try this试试这个

KeyguardManager manager = (KeyguardManager)context.getSystemService(KEYGUARD_SERVICE);
kl = manager.newKeyguardLock("my-remote-app");
kl.disableKeyguard();

//for reenabling keyguard on exit (if you need) //用于在退出时重新启用键盘锁(如果需要)

onDestroy() {
kl.reenableKeyguard();
}

this works <=ICS.这有效<=ICS。 This is a deprecated api, they suggested you to use the flags from WindowManager for similar effect.这是一个已弃用的 api,他们建议您使用 WindowManager 中的标志以获得类似的效果。 Although I failed to generate the similar effect using the WindowManger.虽然我没有使用 WindowManger 产生类似的效果。

Hope this helps,希望这可以帮助,

Please note that I'm not an Android developer, but:请注意,我不是 Android 开发人员,但是:

If you look at this , it looks like you can ask the WindowManager to dismiss the key guard if you have the right permission, even if you're in "secure lock" mode.如果你看看这个,看起来你可以要求 WindowManager 在你有正确的权限的情况下解除密钥保护,即使你处于“安全锁定”模式。

据我所知,我们无法以编程方式解锁受密码保护的手机。

One solution would be to write a "custom lockscreen".一种解决方案是编写“自定义锁屏”。 Sure, it's not the easiest way, but it would work as you can do everything you want with your own lockscreen.当然,这不是最简单的方法,但它会起作用,因为您可以使用自己的锁屏做任何想做的事情。 If you are considering that solution, feel free to contact me, I'll give you some useful links.如果您正在考虑该解决方案,请随时与我联系,我会给您一些有用的链接。 Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM