Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: get current sensor state

Yes, I can get sensor update events with SensorEventListener. But this approach has 2 drwwbacks:

1) For some sensors I have to wait for the state to update. For example, temperature may update after a minute!

2) In some cases I can get incorrect readings. For example, the phone lies on a flat surface and does not move. I receive first orientation update event after listener registration. When only a part of the orientation vector changes, other parts may be 0. And it is no way to determine, is it a true 0 degree azimuth or just an incomplete vector. If I move the phone a little, the correct non-zero azimuth appears.

To solve this problems it's possible to create a separate thread that constantly monitors sensors. After some time it will certainly contain true values. But I think that it is an overhead for such simple task.

Is it any other way to get current sensor data?

like image 945
xvalex Avatar asked Jun 26 '26 05:06

xvalex


1 Answers

Is it any other way to get current sensor data?

Not in the current API, AFAIK, sorry.

like image 74
CommonsWare Avatar answered Jun 28 '26 18:06

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!