Android 开机应用自启无锁屏及保持屏幕常亮

sancaiodm Android源码摘录 2021-11-30 1452 0

//保持屏幕常亮状态    

public static void eepScreenOn(Activity context){

        WakeLock screenLock = ((PowerManager)context.getSystemService(context.POWER_SERVICE)).newWakeLock(

            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");

        screenLock.acquire();

        context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        screenLock.release();

    }

//应用开机自启后无锁屏界面

getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,               WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);


评论