aeric Expert Licensed User Longtime User Aug 29, 2018 #1 I refer to the following sample code: How do I prevent screen timeout I am using ExoPlayer library. When the video plays until 2 minutes, the screen turns dim and then screen lock. I have tried to add the permission in manifest but the screen still sleep. Method 1: Code: Copy AddPermission(android.permission.WAKE_LOCK) Method 2: Code: Copy AddManifestText(<uses-permission android:name="android.permission.WAKE_LOCK" />) I am using Xiaomi Redmi 5 Plus (Android 7.1.2). Is there any setting I need to change in my phone?
I refer to the following sample code: How do I prevent screen timeout I am using ExoPlayer library. When the video plays until 2 minutes, the screen turns dim and then screen lock. I have tried to add the permission in manifest but the screen still sleep. Method 1: Code: Copy AddPermission(android.permission.WAKE_LOCK) Method 2: Code: Copy AddManifestText(<uses-permission android:name="android.permission.WAKE_LOCK" />) I am using Xiaomi Redmi 5 Plus (Android 7.1.2). Is there any setting I need to change in my phone?
BillMeyer Well-Known Member Licensed User Longtime User Aug 29, 2018 #2 You need the "phone" library and then use these examples. Code: Copy Dim ps As PhoneWakeState ps.KeepAlive(True) '<-- Keeps the screen on at set brightness ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again Enjoy !! EDIT: I've just seen that you have done this and that it still sleeps after two minutes - it should not - but there must be a work around - I think the Os is detecting inactivity and forcing a closure - Anyone else with a work around ? Upvote 0
You need the "phone" library and then use these examples. Code: Copy Dim ps As PhoneWakeState ps.KeepAlive(True) '<-- Keeps the screen on at set brightness ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again Enjoy !! EDIT: I've just seen that you have done this and that it still sleeps after two minutes - it should not - but there must be a work around - I think the Os is detecting inactivity and forcing a closure - Anyone else with a work around ?
aeric Expert Licensed User Longtime User Aug 29, 2018 #3 BillMeyer said: You need the "phone" library and then use these examples. Code: Copy Dim ps As PhoneWakeState ps.KeepAlive(True) '<-- Keeps the screen on at set brightness ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again Enjoy !! Click to expand... Yes, I follow the code as Erel shared. Code: Copy Sub Process_Globals Dim pw As PhoneWakeState End Sub Sub Activity_Pause (UserClosed As Boolean) pw.KeepAlive(True) 'set false if brightness is not needed End Sub Sub Activity_Resume pw.ReleaseKeepAlive End Sub Upvote 0
BillMeyer said: You need the "phone" library and then use these examples. Code: Copy Dim ps As PhoneWakeState ps.KeepAlive(True) '<-- Keeps the screen on at set brightness ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again Enjoy !! Click to expand... Yes, I follow the code as Erel shared. Code: Copy Sub Process_Globals Dim pw As PhoneWakeState End Sub Sub Activity_Pause (UserClosed As Boolean) pw.KeepAlive(True) 'set false if brightness is not needed End Sub Sub Activity_Resume pw.ReleaseKeepAlive End Sub
aeric Expert Licensed User Longtime User Aug 30, 2018 #4 It works in emulator but not in my real device. Upvote 0
npsonic Active Member Licensed User Aug 30, 2018 #5 I don't own Xiaomi and can't test this, but there is possibility that Xiaomi just doesn't keep screen on, no matter what you do. It completely depends what manufacturer decides to do and how they modify android. Upvote 0
I don't own Xiaomi and can't test this, but there is possibility that Xiaomi just doesn't keep screen on, no matter what you do. It completely depends what manufacturer decides to do and how they modify android.
aeric Expert Licensed User Longtime User Aug 30, 2018 #6 I don't know if I am doing wrong with the following code but it works for me and make more sense . Code: Copy Sub Activity_Resume pw.KeepAlive(True) 'set false if brightness is not needed player1.Position = pos player1.Play End Sub Sub Activity_Pause (UserClosed As Boolean) pw.ReleaseKeepAlive pos = player1.Position player1.Pause End Sub Upvote 0
I don't know if I am doing wrong with the following code but it works for me and make more sense . Code: Copy Sub Activity_Resume pw.KeepAlive(True) 'set false if brightness is not needed player1.Position = pos player1.Play End Sub Sub Activity_Pause (UserClosed As Boolean) pw.ReleaseKeepAlive pos = player1.Position player1.Pause End Sub