Android Question PhoneSensor paused when screen off

Rizal Putra

Member
Licensed User
Longtime User
I use PhoneSensor(Accelerometer) in some Service, but when screen turned off PhoneSensor paused.

How to make PhoneSensor always running though screen turned off ?
 
Last edited:

lemonisdead

Well-Known Member
Licensed User
Longtime User
Sorry, but still doesn't work for me.
I saw this behaviour on some devices. Which is the one it doesn't work on, please ?

The solution, Erel proposed to me previously, was to reactivate the sensor when the screen goes off. It worked on some devices. Perhaps could you try ?
 
Upvote 0

tmav

Member
Licensed User
Longtime User
I have the same problem with Prestigio pmt3377_wi.

How did you solved this problem?
How I can reactivate the sensor when the screen goes off?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
How I can reactivate the sensor when the screen goes off?
Hello,
You will have to listen to PhoneEvents and when you get the ScreenOff event, you simply redo a [Sensor].StartListening

Does it work for you ?
 
Upvote 0

tmav

Member
Licensed User
Longtime User
Hello,
I tried the following, but still not working.
I have 3 other devices that my code is working, but not on this one.

B4X:
Sub PE1_ScreenOff (Intent As Intent)
    LogD("Screen is OFF")
'    p.PartialLock
    ps.StartListening("Sensor")
'    AddSensor(ps.TYPE_ACCELEROMETER, "ACCELEROMETER", True)
End Sub
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Another solution is to try using your own lockscreen (thanks to this useful post : https://www.b4x.com/android/forum/t...reen-with-just-5-lines-of-code.43327/#content). From my experience the mobiles where the PartialLock is not working were using "special" lockscreens which manage the mobile's battery saving policy. Perhaps could you try too.

A question only because I saw the "p.PartialLock" from inside the ScreenOff event. Have you already tried to put it in Activity_Resume ?
 
Upvote 0

tmav

Member
Licensed User
Longtime User
Another solution is to try using your own lockscreen (thanks to this useful post : https://www.b4x.com/android/forum/t...reen-with-just-5-lines-of-code.43327/#content). From my experience the mobiles where the PartialLock is not working were using "special" lockscreens which manage the mobile's battery saving policy. Perhaps could you try too.

A question only because I saw the "p.PartialLock" from inside the ScreenOff event. Have you already tried to put it in Activity_Resume ?

I have the p.PartialLock in the Activity_Resume.
What I am trying is to wake up the device with a shake.
This is my test application.
Press start service to start the service that monitor every 10seconds the accelerometer for a shake and wake up the device.

This is the log:
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
06/12/2015 16:29:52 : Activity Resume
Partial wakeLock already held.
06/12/2015 16:30:05 : Start Click
** Service (servicem) Create **
ACCELEROMETER MaxValue = 19.613300323486328
06/12/2015 16:30:05 : Create Service
** Service (servicem) Start **
06/12/2015 16:30:05 : Start Service
06/12/2015 16:30:05 : BatteryChanged: Level = 84, Scale = 100, Plugged = false
06/12/2015 16:30:10 : timer1 tick
** Service (servicem) Start **
06/12/2015 16:30:15 : Start Service
WakeLock already held.
WakeLock already held.
WakeLock already held.
WakeLock already held.
WakeLock already held.
WakeLock already held.
06/12/2015 16:30:20 : timer1 tick
06/12/2015 16:30:25 : BatteryChanged: Level = 84, Scale = 100, Plugged = false
** Service (servicem) Start **
06/12/2015 16:30:25 : Start Service
06/12/2015 16:30:30 : timer1 tick
No wakelock.
** Service (servicem) Start **
06/12/2015 16:30:35 : Start Service
** Activity (main) Pause, UserClosed = false **
06/12/2015 16:30:35 : Activity Pause
06/12/2015 16:30:35 : Screen is OFF
06/12/2015 16:30:40 : timer1 tick
No wakelock.
** Service (servicem) Start **
06/12/2015 16:30:45 : Start Service
06/12/2015 16:30:50 : timer1 tick
No wakelock.
** Service (servicem) Start **
06/12/2015 16:30:55 : Start Service
** Activity (main) Resume **
06/12/2015 16:30:55 : Activity Resume
Partial wakeLock already held.
06/12/2015 16:30:55 : Screen is ON
WakeLock already held.
WakeLock already held.
WakeLock already held.
WakeLock already held.
06/12/2015 16:31:00 : timer1 tick
** Activity (main) Resume **
 

Attachments

  • service_sensor.zip
    5.1 KB · Views: 199
Upvote 0
Top