简体   繁体   中英

Does sampling rates of sensors change when update the API version on the same device?

As in the title, I am wondering whether the pre-defined sampling rates of sensors could change when I updated the android version on my device from API 26 to API 28, for example?

In detail, assume I put the sampling rate for the accelerometer and gyroscope sensors at 100 Hz when the device Galaxy Samsung S8's android version has API 26. Then if I update the Android version to API 28, would that change or affect the sampling rates of the two sensors?

I searched a lot but could not find an official answer or resources. Please, if could answer or share some useful links, that would be highly appreciated.

In short -- No, an API Level Change won't influence your sensor sampling rate. Nothing has changed in that field since API Level 3 (esp. adding the possibility to specifiy your own sampling rate). The main link for this topic is on Monitoring Sensor Events in the official Android Dev Docs.

A bit extensive quoting for your interest:

The data delay (or sampling rate) controls the interval at which sensor events are sent to your application via the onSensorChanged() callback method. The default data delay is suitable for monitoring typical screen orientation changes and uses a delay of 200,000 microseconds. You can specify other data delays, such as SENSOR_DELAY_GAME (20,000 microsecond delay), SENSOR_DELAY_UI (60,000 microsecond delay), or SENSOR_DELAY_FASTEST (0 microsecond delay). As of Android 3.0 (API Level 11) you can also specify the delay as an absolute value (in microseconds).

But pay attention, that specifying 100 Hz (so a delay of 10 microseconds) doesn't guarantee that rate anyway:

The delay that you specify is only a suggested delay . The Android system and other applications can alter this delay. As a best practice, you should specify the largest delay that you can because the system typically uses a smaller delay than the one you specify (that is, you should choose the slowest sampling rate that still meets the needs of your application). Using a larger delay imposes a lower load on the processor and therefore uses less power.

Of course the question arises, what rate do one get:

There is no public method for determining the rate at which the sensor framework is sending sensor events to your application; however, you can use the timestamps that are associated with each sensor event to calculate the sampling rate over several events.

Therefore you can write a small test program or use an existing one, there are plenty of them on Github.

But the mere update of the API Level shouldn't change anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM