简体   繁体   English

使用DevicePolicyManager .lockNow()后无法解锁手机

[英]Can't unlock my phone after using DevicePolicyManager .lockNow()

I come here cause i create an android app which switch off the screen (by locking it) with .lockNow(). 我来这里是因为我创建了一个Android应用,该应用通过.lockNow()关闭屏幕(通过锁定屏幕)。

This is my code : 这是我的代码:

btnToSleep.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            time = Integer.parseInt(timeBeforeSleep.getText().toString());

            m_handlerTask = new Runnable(){
                @Override
                public void run() {
                    if(time > 0){
                        Log.i("timeleft",""+time);
                        time--;
                    }else{
                        m_handler.removeCallbacks(m_handlerTask); // cancel run
                        dpm.lockNow();

                        MainActivity.this.finish();
                    }
                    m_handler.postDelayed(m_handlerTask, 1000);
                }
            };
            m_handlerTask.run();
        }
    });

This work but i can't unlock my phone after :( . If you know a way to solve it I will very happy :D. Thanks in advance. 这项工作,但:(之后,我无法解锁手机。如果您知道一种解决方法,我会很高兴:D。预先感谢。

You may want to look into using the PowerManager to tell your device to go to sleep. 您可能想研究使用PowerManager告诉设备进入睡眠状态。 It should have the same effect as pressing the power button to turn off the screen. 它应具有与按下电源按钮以关闭屏幕相同的效果。

http://developer.android.com/reference/android/os/PowerManager.html#goToSleep(long) http://developer.android.com/reference/android/os/PowerManager.html#goToSleep(long)

You will need to add the DEVICE_POWER permission to use it. 您将需要添加DEVICE_POWER权限才能使用它。

If you want an app to be able to actually enable the lock screen, I believe that has to be done through Device Administration 如果您希望某个应用程序能够真正启用锁定屏幕,我认为必须通过设备管理来完成

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

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