Get Accelerometer / Compas Values without listener

Can I access the global accelerometer and compass values without using a listener?

What I want is to be able to get these values at any time in my code rather than using a listener to update some global variables?

[import]uid: 5354 topic_id: 754 reply_id: 300754[/import]

At the moment, you’re limited to the listener. You could write a small utility function to add the listener which will get the value and update the global, and immediately remove the listener, so it only happens once. I know that’s a bit weird but it’ll work. [import]uid: 54 topic_id: 754 reply_id: 1538[/import]

Hi, Matthew. One thing to note is that activating hardware listeners generally TURNS ON hardware or sensors that are off by default. Having all hardware activated at all times is a bad practice in the mobile world, since it would drain the battery more rapidly.

Also, the hardware itself doesn’t actually store values, it literally sends out events from time to time. For example, once the GPS gets your position, it doesn’t do anything more until your position changes, and then it fires a new location event. (iPhone and Android work in roughly the same way.)

Also note that some sensor data isn’t available in realtime – there’s some caching on the OS to make it faster to get a rough position, but in reality it can take 30 seconds or more for fresh data to start flowing out of the GPS. In short, we have an event-based framework for these things because the data itself is really event-based. [import]uid: 3007 topic_id: 754 reply_id: 1548[/import]