问题描述
我一直在试图通过程序来锁定设备。但我不能找到解决办法仍。我想通过程序来锁定机器人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.
我的应用程序是远程锁定设备。当接收到一些code字消息来锁定则锁定手机。请指引我。我发现有很多Api_demo程序作为解决方案,但我不能提取锁code单独从并找到解决办法。
My app is to remote lock the device. When message is received with some code words to lock then it locks the phone. Please guide me. I have found many Api_demo program as solution but I can't extract lock code alone from that and find solution.
推荐答案
活动类应该是内部类和outter类应该扩展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);
}
}
}
要锁定设备写入code在您使用锁定事件
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设备编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!