Android 锁屏状态下后台弹出界面

1.唤醒屏幕

 private PowerManager.WakeLock mWakeLock;
    private PowerManager mPowerManager;

    @SuppressLint("InvalidWakeLockTag")
    public void turnOnScreen() {
        // turn on screen
        try {
            mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
            mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
            mWakeLock.acquire();
            mWakeLock.release();
        } catch (Exception e) {

        }
    }

2.在oncreate 中加入

   getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED //锁屏显示
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解锁
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕不息屏
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);//点亮屏幕
        super.onCreate(savedInstanceState);

3.跳转Activity时

 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)

4.声明权限



    
    
    
    

你可能感兴趣的:(Android 锁屏状态下后台弹出界面)