自定义app锁屏页

 Window win = getWindow();
        win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
        );//锁屏状态下显示
//                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD ;//解锁
//                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕长亮
//                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //打开屏幕
        ;

        try {
            //使用手机的背景
            Drawable wallPaper = WallpaperManager.getInstance(this).getDrawable();
            win.setBackgroundDrawable(wallPaper);
        } catch (Exception e) {
            //有些手机获取不到手机背景图
            e.printStackTrace();
            this.finish();
            return;
        }
if(Build.VERSION.SDK_INT>=26){
    try{
        KeyguardManager keyguardManager = (KeyguardManager) LockScreenActivity.this.getSystemService(KEYGUARD_SERVICE);
        keyguardManager.requestDismissKeyguard(LockScreenActivity.this, new KeyguardManager.KeyguardDismissCallback() {
            @Override
            public void onDismissError() {
                super.onDismissError();
            }

            @Override
            public void onDismissSucceeded() {
                super.onDismissSucceeded();
            }

            @Override
            public void onDismissCancelled() {
                super.onDismissCancelled();
            }
        });
    }catch (Exception e){
        e.printStackTrace();
    }

}

 

 

 

你可能感兴趣的:(android)