Phoneevents

SoyEli

Active Member
Licensed User
Longtime User
Can anybody tell me if it's possible to turn screen on with phone events or any othere event in a android app ???
I tried "PhoneWakeState" with no luck.


THANK YOU for your HELP :sign0163:

:sign0163: :sign0163: :sign0163:
 

salmander

Active Member
Licensed User
Longtime User
It is not possible to turn the screen on programmatically. You can prevent it from going to sleep with PhoneWakeState.
Hi Erel,

you are saying it is not possible to turn the screen on programmatically, then how does screen turns on when the alarm goes on? Anyway to simulate the same method?
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Can you share how to turn the screen on? Thank you.
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Hi susu, first of all you need to understand that you can't run the activity module while the screen is off. So you need to create a dedicated service which will turn the screen on and then start the activity. And then, to release the phonewakestate you need to call it outside of the activity pause or if the userclosed is true. Here is the sample code to make you better understand.
B4X:
'service module
Sub Service_Start (StartingIntent As Intent)
   Dim p As PhoneWakeState
   Log("releasing KeepAlive")
   p.ReleaseKeepAlive
   Log("turning screen on")
   p.KeepAlive(True)
   Log("using partialLock")
   p.PartialLock
   StartActivity(Activity1) ' start the activity
   ' destroy this service once the activity is started.
   StopService("")
End Sub

' Activity module
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True then
    Dim p As PhoneWakeState
    p.ReleaseKeepAlive
    p.ReleasePartialLock

End If

End Sub
let me know if you need more help.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Thank you so much. I'll try your code when I'm home.
 
Upvote 0

Xardoz

Member
Licensed User
Longtime User
For other beginners who find this post.

Load the Phone Library

Name your Activity Module Activity1

Obvious for the pros, but it will save time for the rest of us :)
 
Last edited:
Upvote 0
Top