Disable/Delay Android Lock Screen Programmatically

后端 未结 3 1584
南旧
南旧 2021-01-02 10:59

I’d like to disable/delay the lock screen programmatically. In looking into this, KeyguardManager is depreciated/doesn\'t work consistently,

相关标签:
3条回答
  • 2021-01-02 11:16

    try this, it will keep awake the screen/ display , as long as the activity is on top. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    Also this does not require any permission in manifest.

    0 讨论(0)
  • 2021-01-02 11:19

    Did you try this?

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();
    

    Add

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

    You can disable the keyguard using this.

    0 讨论(0)
  • 2021-01-02 11:29

    the answer of @nandeesh is working but it's deprecated , to disable lock screen use flags :

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    
    0 讨论(0)
提交回复
热议问题