The phone's sensors fall asleep when the screen is turned off

Hello. I plan to use the smartphone's built-in sensors to record the angular position. The problem is that they stop being polled when the screen is blanked. For the GPS sensor, as I see, there is an extension that fixes the problem. And what about accelerometers and an angular position sensor?


I didn't know that any Smartphone had an angular position sensor.

You can force the screen to stay on using Taifun's tip:

Yes depending on how you need to have it work. You might modify Extension with Rush. Keep the app running. Doze mode. Service. Notification. Source code . This free extension does work with the GPS receiver (what I use successfully) and it should do what you hope to. It should work with accelerometers too. You have to modify it to work even when the app screen is not showing and you are doing other things on your phone.

This extension Background Tasks extension [3.8 A] 🥳 should also work .

How do you use them? Please read the threads and modify and experiment. Adapting these stool to work with any specific Project is complex. Experiment and learn a lot.

A constantly on screen drains the battery. At the same time, the phone is used as a recorder and transmitting device on an experimental stand, and there is no one to look at this screen. It is also interesting that the time interval between reading information from the sensor is not constant and is quite significant (up to 60 ms). As far as I understand, Ap Inventor does not allow you to manage it.
Sensor_angle.aia (64.1 KB)

... I see, you mean the orientation sensor. The data from the sensor should not change, it is expected that the smartphone is not moved. So if the stand is moving the phone, it cannot be a smooth continuous movement, it will need to be incremental - move - stop:read sensor values - move. So reading the data will be consistent providing the movement is accurately controlled (and the sensor is of good quality).

The data continues to be updated with a frequency of 40-50 msec and on the phone lying on the table. Apparently, this is due to the spread of the readings of the sensor itself. You can check this by running the emulation on a real smartphone.

That is entirely dependent on the phone, I wouldn't expect any consistency across the range of phones from one manufacturer, never mind several manufacturers.

If you want more control, use an external microcontroller fitted with a high quality sensor.

I usually use AndroSensor, it quite correctly records readings even when the screen is off. But it does not average readings between recording intervals, and this leads either to a large file volume requiring further processing, or to a loss of accuracy. Unfortunately, Fiv Asim did not respond to my request to finalize the program.

How long does the App have to run for?

The duration of the work is about eight hours.

To achieve that, you can use the extension 'Background Tasks', but depending on your Smartphone, Taifun's tip on keeping the screen on is probably viable - you can turn the screen brightness right down and the App can display a fully black screen (Virtual Screen). Why not experiment?