简体   繁体   中英

Android Periodic Sensor Data

For an Android App, that will show the value of an internal sensor (eg Acceleration) in a graph, i need to find a way to access this signal periodically. At the moment i am using a SensorEventListener , but unfortunately this only gives me the possibility to get a value whenever it changes. Since I want to display the graph (point to point) in dependency of the time, this means it would directly draw a line from the old to the new value (and if the old value has been a long time, it looks like a linear changing of the value). So my question: How can I get access to a sensor's data periodically?

The documentation for SensorManager says that registerListener(android.hardware.SensorEventListener, android.hardware.Sensor int)

"Registers a SensorEventListener for the given sensor at the given sampling frequency."

To get these events, though, your application would need to be active (hold a partial wake lock). It would be better to do this in a background service so that the application doesn't need to remain active. See for example, SensorEventListener in a service

So in the end i used a timer, which checked the values from my sensor, which I put into an array, periodically. Unfortunately registerListener didnt work, since the value is just a suggestion for the system. Thanks though for the help.

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