以编程方式锁定 Android 设备 [英] Lock the Android device programmatically

查看:33
本文介绍了以编程方式锁定 Android 设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过程序锁定设备.但我仍然找不到解决方案.我想通过程序锁定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.

推荐答案

activity 类应该是内部类,外部类应该扩展 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 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆