Ask / Submit

[Bug] Accelerometer does not respect alwaysOn [answered]

asked 2015-02-23 01:18:40 +0300

Kim gravatar image

In my Pedometer project, I need the accelerometer to stay on, even when the screen is off.

Code example:

 Accelerometer {
       id: accel
       dataRate: 100
       alwaysOn: true  // <====
       onActiveChanged: canvas.requestPaint();
       onReadingChanged: { ... }

The manual states:

alwaysOn : bool
This property holds a value to indicate if the sensor should remain running when the screen is off.

Some platforms have a policy of suspending sensors when the screen turns off. Setting this property to true will ensure the sensor continues to run.

But even though I have alwaysOn set to true, the onReadingChanged does not fire when the screen is off!

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by Kim
close date 2018-06-07 10:43:57.265536


Ah, that's the reason. I like the Pedometer but ran into this issue.

lispy ( 2015-02-23 09:00:35 +0300 )edit

Good question Kim! Please tell us if you find a solution. I will start working with an application that requires this feature at some point when I have time. By the way, your pedometer looks great!

pekkeli ( 2015-02-23 20:57:20 +0300 )edit

I'll add a comment here as soon as I have a verified solution.

Kim ( 2015-02-24 01:45:59 +0300 )edit

KeepAlive did indeed solve the problem. I had some problems finding out how to install and distribute it, but discovered that KeepAlive is distributed with the OS! All I had to do was:

import org.nemomobile.keepalive 1.1

and somewhere appropriate:

KeepAlive.enabled = true;

Keepalive isn't known by QTCreator, so the include will be marked as unknown, but on the device it works!

Kim ( 2015-03-03 23:40:29 +0300 )edit

2 Answers

Sort by » oldest newest most voted

answered 2015-02-23 19:23:38 +0300

MartinK gravatar image

Try with org.nemomobile.keepalive- that might possibly prevent the suspend Sailfish OS normally does when the screen is turned off (at least it work for keeping the GPS running when the screen is off for track recording in modRana):

import org.nemomobile.keepalive 1.1

Accelerometer {
    KeepAlive {
        enabled: true
       id: accel
       dataRate: 100
       alwaysOn: true
       onActiveChanged: canvas.requestPaint();
       onReadingChanged: { ... }
edit flag offensive delete publish link more


I'll have a look at it, thanks. Funny I have never had any problems with the GPS, and as far as I know, my OSMapper app runs great on the device with the screen off! Well maybe I should give it a test again ;)

Kim ( 2015-02-24 01:44:25 +0300 )edit

Well I have been trying to implement keepAlive, but as I have never used any plugins to QML before, I just cannot find out how to install it (ie. make it accessible from my program), or how to make my rpm require it under installation!

Can anyone explain?

Kim ( 2015-02-25 00:02:38 +0300 )edit

answered 2016-05-02 07:42:23 +0300

Rikujolla gravatar image

updated 2016-05-02 07:43:42 +0300

I got his work by both using active and alwaysOn. (SailfishOS vesion Saimaa)

Accelerometer {
    alwaysOn: true
    dataRate: 2
    onReadingChanged: console.log(reading.x,reading.y,reading.z)
edit flag offensive delete publish link more

Question tools



Asked: 2015-02-23 01:18:40 +0300

Seen: 363 times

Last updated: May 02 '16