Android Question Vibrate phone when asleep

jimseng

Active Member
Licensed User
Longtime User
Hello.
I have an application that communicates with a Raspberry pi using Bluetooth serial. I have a routine on the Pi that sends a (serial) message to report a task is complete and my B4a app receives the message and vibrates the phone (a long vibrate) so I can tell when the task is complete even if the phone is in my pocket. However if the task take long enough for my screen to turn off I don't get the vibrate alert. Using:
B4X:
Dim awake As PhoneWakeState
        awake.KeepAlive(True)
My phone screen turns on but only to the lock screen, not the application and the vibrate doesn't happen, even though it is part of the same subroutine that wakes the phone. I don't really need to look at the phone, just feel the vibration.
Any suggestions?
 

jimseng

Active Member
Licensed User
Longtime User
I'm not running any of this in a service so I'm a bit confused as to whether it will receive any serial data when paused. However. Using
B4X:
Dim awake As PhoneWakeState
        awake.KeepAlive(True)
turns the screen on to the lock screen.
Using:
B4X:
Dim r As Reflector
        r.Target = r.GetActivity
        r.Target = r.RunMethod("getWindow")
        r.RunMethod2("addFlags", 6815872, "java.lang.int")
doesn't, although the phone then stays on once I have unlocked it myself.
And I am using:
B4X:
Dim pv As PhoneVibrate
        pv.Vibrate(1000)
to vibrate the phone currently.
Given that the awake.KeepAlive turns the screen on it suggests to me that my subroutine is getting called (from AStream_NewData)
I can use the keepalive to keep the screen on dim until the event has occurred, which is fine, but I want to try and learn a better way.
I'll look at high importance notification but any pointers would be appreciated.
 
Upvote 0
Top