以编程方式锁定 Android 设备

发布于 2024-10-09 06:44:10 字数 198 浏览 4 评论 0原文

我一直试图通过程序锁定设备。但我仍然找不到解决方案。 我想通过程序锁定Android froyo2.2。我尝试过 keyguardmanager 和 DeviceAdminManager。

我的应用程序是远程锁定设备。当收到带有一些要锁定的代码字的消息时,它就会锁定手机。我找到了许多 Api_demo 程序作为解决方案,但我无法从中单独提取锁定代码并找到解决方案。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

各空 2024-10-16 06:44:10

Activity 类应该是内部类,外部类应该扩展 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);
      }
   }
}

要锁定设备,请在用于锁定的事件中编写代码。

if (active) {
mDPM.lockNow();
}

如果启用了 DeviceAdmin,则手机将被锁定。
要启用设备管理,将调用 DevicePolicyManager 意图,并且应由用户启用它。

Intent intent = new   Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);  
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);        

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

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);        
闻呓 2024-10-16 06:44:10

为了解决此任务,您可以查看 NoKeyGuard 源代码更准确地说,是 NoKeyGuard Service 类和 KeyguardLockWrapper 类。

要解锁设备,请在使用解锁的情况下写入代码:

    Context context= getApplicationContext();
    KeyguardManager _guard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock _keyguardLock = _guard.newKeyguardLock("KeyguardLockWrapper");
    //to disable
    _keyguardLock.disableKeyguard();
    //to enable
    _keyguardLock.reenableKeyguard();

In order to solve this task you can take a look to NoKeyGuard source code and more precisely to a NoKeyGuard Service class and KeyguardLockWrapper class.

To unlock the device write the code in the event where you use to unlock:

    Context context= getApplicationContext();
    KeyguardManager _guard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardLock _keyguardLock = _guard.newKeyguardLock("KeyguardLockWrapper");
    //to disable
    _keyguardLock.disableKeyguard();
    //to enable
    _keyguardLock.reenableKeyguard();
还不是爱你 2024-10-16 06:44:10

Activity 类应该是内部类,外部类应该扩展 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);
  }
 }
}

The activity class should be the inner class and the outer 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);
  }
 }
}
另类 2024-10-16 06:44:10
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 0;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 0;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文