Search code examples
androidaccelerometer

Get a single accelerometer value


I'm working on adding a calibration feature to an accelerometer-driven game. For the calibration, I need a single value from the accelerometer. Should I register a listener, get the first value it gives me, and unregister it, or is there a better way to get just one value?


Solution

  • Basically there is no way to do get a single value as far as I can tell. What I ended up doing is putting in a variable called lastAccelValue and registering my Activity to listen for accelerometer updates at the slowest possible speed. Each new accelerometer value is stored to lastAccelValue.