Android Question Wake Phone

Jonathan Rigley

Member
Licensed User
Longtime User
Hi,

I use :

B4X:
StartServiceAt(svcAlarm, DateTime.Now, True)

and Sticky Service to start a service. The service looks through a database for the current date and time. If found it starts an activity.

I know the database is looking because I've used ToastMessageShow to show the service is running. If the phone screen is on the alarm activates but if the phone screen is off it doesnt work.

Ive tried:

B4X:
Dim oPhoneWakeState As PhoneWakeState
        oPhoneWakeState.ReleaseKeepAlive
        oPhoneWakeState.KeepAlive(True)

To wake the phone but no luck.

Can any one help?

Jonathan
 

Jonathan Rigley

Member
Licensed User
Longtime User
Hi Erel, thanks for replying.

The service is running with the screen off. The strange thing is. Whilst connected to B4A all works well but as soon as I disconnect the wireless it won't fire the alarm.
My guess is because B4A keeps the phone awake.

Jonathan
 
Upvote 0

Chandrashekhar

Member
Licensed User
Longtime User
I use following modifided code from erel's showwhenlocked to wakeup my device if its screen off. Hope its help you.
B4X:
 Dim r As Reflector
  Log("set")
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2("addFlags", 524288, "java.lang.int")
 
Upvote 0

Jonathan Rigley

Member
Licensed User
Longtime User
Thank you for your reply, I tried the above code but it didn't work for me. It's as if the service stops running. I've also tried Service.StartForeground but to no avail.

Jonathan
 
Upvote 0

Jonathan Rigley

Member
Licensed User
Longtime User
Just for information:

I started a separate application with a service containing a 30 second timer. The timer contained PhoneWakeState and a 1 second vibrate. I started the service with StartServiceAt(svcStartAlarm, DateTime.Now, True) and made it a sticky service. I ran the app and switched the phone off. It work for about 4 minutes then stopped working.

I tried Service.StartForeground but this only worked for a minute before stopping. These have been run on a factory reset Samsung Galaxy s5 with kitkat.

Its my best guess that the service is being killed.

Jonathan
 
Upvote 0

Jonathan Rigley

Member
Licensed User
Longtime User
Thanks Erel, that worked perfect on my daughters S3 but still not on mine. Thinking this could be an android issue or bug. Thank you for your help.
 
Upvote 0
Top