Android Question Wake Phone

dgoss

Member
Licensed User
Longtime User
using this

B4X:
Sub GetScreen
    If Not(IsScreenOn) Then
        startactivity("what ever activity name")
    End If
End Sub

B4X:
Sub IsScreenOn As Boolean
    Dim R As Reflector
    R.Target = R.GetContext
    R.Target = R.RunMethod2("getSystemService", "power", "java.lang.String")
    Return R.RunMethod("isScreenOn")
End Sub

with this in the "what ever activity" activity resume and pause

B4X:
Dim r As Reflector
    r.Target = r.GetActivity
    r.Target = r.RunMethod("getWindow")
    r.RunMethod2("addFlags", 6815872, "java.lang.int")

and the release
B4X:
Dim r As Reflector
    r.Target = r.GetActivity
    r.Target = r.RunMethod("getWindow")
    r.RunMethod2("clearFlags", 6815872, "java.lang.int")

works great on Android 5 but on Android 7 it does not wake the phone.
Any pointers as to why appreciated
 

dgoss

Member
Licensed User
Longtime User
Hi all

been playing with this but I've hit a brick wall
I,ve uploaded a sample file, the sample works on a timer to wake the phone.
it supposed to wake the phone up and show Activity ,this works on Android <7 but not on Android 7.

any help appreciated
 

Attachments

  • wake phone test.zip
    12.2 KB · Views: 353
Upvote 0

dgoss

Member
Licensed User
Longtime User
I haven't checked your code. A timer is not good enough. You need to call StartServiceAt or better SetExactAndAllowWhileIdle: https://www.b4x.com/android/forum/t...estartatexact-not-accurate.65117/#post-412286

Start an activity from the service and acquire a wake lock with PhoneWakeState.

Hi Erel Thx For reply

the timer is only for testing purposes , the actual app is to big to upload so I created a sample app that recreates what is (or not) happening.
the project a driving timer for HGV drivers in the EU and is using gps in a service to wake up phone when certain conditions are met.

the phone i'm testing on Huawei p8 lite, never had a problem on previous Huawei's or Samsung,Lenovo just this one
again great stuff in here and the help is phenominal
 
Upvote 0
Top