2

我正在寻找一种从我的应用程序启动本机 android 锁屏的方法。我环顾四周,找到了关于 KeyGuardLock 和 KeyGuardManager 的代码,但我相信这只会使键盘无法工作。

参考:http ://smartandroidians.blogspot.com/2010/03/enabling-and-disabling-lock-screen-in.html

4

1 回答 1

0

使用 DevicePolicyManager 锁定屏幕..

这是怎么做的:http: //developer.android.com/reference/android/app/admin/DevicePolicyManager.html

开锁..

    keyGuard = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        mLock = keyGuard.newKeyguardLock("Your_App");
        mLock.disableKeyguard();

唤醒屏幕..

        PowerManager pm = (PowerManager) getApplicationContext()
                .getSystemService(Context.POWER_SERVICE);
        WakeLock wakeLock = pm
                .newWakeLock(
                        (PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                                | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP),
                        "TAG");
        wakeLock.acquire();
于 2014-02-27T06:21:27.640 回答