“Custom” sensor event rates don't seem to work with SensorManager.registerListener(SensorEventListener listener, Sensor sensor, int rate)

UPDATED:

I was able to solve the specific problem I was having by introducing a class-scope static counter and just ignoring ever x number of events. But I'd still like to know what I'm doing wrong re: registering the listener with a hint in microseconds instead of using one of the four given constants.


An Activity in my app is engaging the sensors to obtain the orientation of the device, determine the roll, and utilize it.

I am using

SensorManager.registerListener(SensorEventListener listener, Sensor sensor, int rate)

to register my sensors. From the Android Documentation for this method:

Parameters

[...]

rate

The rate sensor events are delivered at. This is only a hint to the system. Events may be received faster or slower than the specified rate. Usually events are received faster. The value must be one of SENSOR_DELAY_NORMAL, SENSOR_DELAY_UI, SENSOR_DELAY_GAME, or SENSOR_DELAY_FASTEST or, the desired delay between events in microsecond.

If I use one of the 4 predefined constants then the app works fine; however these constants all provide rate hints that are too fast for my needs. I have to send out a UDP packet containing some information with every event change, and the receiving end seems to be getting completely inundated with messages using any of the predefined rates. Using an integer number like 30000 (since the API specifies quantities in microseconds) causes the app to stop reporting sensor events all together.

What am I missing that is preventing me from using my own event rate hints?

6
задан Doug Stephen 3 May 2011 в 18:12
поделиться