I am new to android and working on accelerometer. I want to collect 20 samples of x,y,z per second, for this can I use the following? registerListener(SensorEventListener listener, Sensor sensor, int rate)in the int rate can I use 3000000(microseconds) so that I get one x,y,z value for every 3000000(microseconds) or 3 seconds so it would be like registerListener(this, Accelerometer , 3000000); and get 20 samples of x,y,z in 1 seconds. If I am wrong can anyone suggest me how to solve this?
Share
Check out the Javadocs for SensorManager.registerListener()
You need to pass in one of the 4 constants, you cannot enter an arbitrary value like you are trying to do.
so an example call might look like this:
EDIT: Tim.footInMouth() I didn’t see the last part of the definition. You can actually pass it microseconds.
I think the math for your seconds is off a little
You want 20 samples per second (1000 milliiseconds)
So you want 1 sample per 50 milliseconds
A microsecond is 1/1000 of a millisecond
So 1000 microseconds = 1 milisecond
and 50,000 microseconds = 50 millisecond = 20 times per second.
So your call should be: