0

我想在通话结束时自动锁定屏幕锁定(滑动、图案、密码或密码)。

例如,当设备设置模式锁定和屏幕灯关闭时,当屏幕灯亮并且 UI 在屏幕上时,得到 Skype 呼叫,它通过密码。断开呼叫后,重置该系统锁定。

我用下面的代码成功绕过了锁:

允许 :

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

解锁设备代码:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if(!pm.isScreenOn()) {
    sendNotification("CALL_STATE_IDLE_SRC_OFF");
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(TAG);
    lock.disableKeyguard();
    wl.acquire();
    wl.release();
} else {
    sendNotification("CALL_STATE_IDLE_SRC_ON");
}
Intent intent = new Intent(this, Name_of_Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP 
                | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT 
                | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
        + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
        + WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
intent.putExtra("Call", "true");
getApplicationContext().startActivity(intent);

但是当我的通话结束时我无法锁定设备。

锁具代码:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(TAG);
        lock.reenableKeyguard();
4

0 回答 0