Programmatically disable screen timeout

前端 未结 2 674
轻奢々
轻奢々 2021-01-22 06:38

From this post, Android disable screen timeout while app is running, I can disable screen timeout by

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSC         


        
相关标签:
2条回答
  • 2021-01-22 07:06

    Do you just want the screen to time out after you've closed your application? Or is something inside your application going to reset the screen timeout so that it will happen even while your app is running?

    If the former I don't think you need to do anything, when you're app is stopped the screen timeout will return to normal.

    If the latter it seems like the snippet you've provided would do the trick. But I have no experience with it so I couldn't be certain.

    0 讨论(0)
  • 2021-01-22 07:15

    Yes, that will work - it's how I do it in PocketSat3, though I don't toggle FLAG_FULLSCREEN (of course, that said - that app doesn't use FLAG_FULLSCREEN...)

    Unlike using WakeLock, doing it this way doesn't require any permissions - though I have to admit it's not completely clear to me that is a Good Thing.

    0 讨论(0)
提交回复
热议问题