Android,Lock设备实用

时间:2016-02-12 06:09:51

标签: android security lockscreen system-setting

我想在完成通话后自动锁定屏幕锁定(滑动,模式,密码或引脚)。

例如,当设备设置模式锁定和屏幕指示灯熄灭时,获取Skype呼叫时间屏幕亮起并且UI在屏幕上,它通过密码。 断开呼叫后,重置该系统锁定。

我使用以下代码成功绕过锁定:

许可:

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

0 个答案:

没有答案