问题描述
我一直试图通过程序锁定设备.但是我仍然找不到解决方案.我想通过程序锁定Android froyo2.2.我已经尝试过keyguardmanager和DeviceAdminManager.
I have been trying to lock the device through program. But I can't find the solution still.I want to lock Android froyo2.2 through program. I have tried keyguardmanager and DeviceAdminManager.
我的应用程序是远程锁定设备.当收到带有一些代码字要锁定的消息时,它将锁定电话.我已经找到了许多Api_demo程序作为解决方案,但是我无法从中单独提取锁定代码并找到解决方案.
My app is to remote lock the device. When message is received with some code words to lock then it locks the phone. I have found many Api_demo program as solution but I can't extract lock code alone from that and find solution.
推荐答案
活动类应该是内部类,而外部类应该扩展DeviceAdminReceiver
The activity class should be inner class and the outter class should extend DeviceAdminReceiver
public class adminActivity extends DeviceAdminReceiver {
public static class Controller extends Activity {
DevicePolicyManager mDPM;
ComponentName mDeviceAdminSample;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(Controller.this,
adminActivity.class);
}
}
}
要锁定设备,请在用于锁定的情况下编写代码
To lock the device write the code in the event where you use to lock
if (active) {
mDPM.lockNow();
}
如果启用了DeviceAdmin,则电话将被锁定.要启用设备管理员,将调用DevicePolicyManager意图,并且用户应启用它.
If DeviceAdmin is enabled then the phone will be locked.To enable the device admin, the DevicePolicyManager intent is called and it should be enabled by the user.
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
这篇关于以编程方式锁定Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!