views:

450

answers:

0

This seems to be a well-known issue right now, but the accepted workaround doesn't seem to be working for us.

On the BlackBerry Storm (JDE 4.7, standard set of 4.7+ simulators), the following bit of code registers an AccelerometerListener. The listener does not get called on the first change in device orientation, but does get called on every subsequent change in orientation.

net.rim.device.api.system.AccelerometerSensor.Channel channel;

void registerAccelerometerListener()
{
    if ( AccelerometerSensor.isSupported() )
    {
        channel = AccelerometerSensor.openOrientationDataChannel(
            Application.getApplication());

        channel.setAccelerometerListener(this);
        // this class does indeed implement the AccelerometerListener interface
    }
}   

public void onData(AccelerometerData data)
{
    // should be called on every orientation change, 
    // but is only called on the second (and subsequent) orientation 
    // change, ignoring the first.
}

With the above code, launching the app in portrait mode, then flipping the device on its side (or making any other orientation change) should force the accelerometer to call onData() of the listener. This does happen, but only on the second and each subsequent flip of the device. The first orientation change is always ignored.

The accepted solution floating around the net seems to be to force call:

Ui.getUiEngineInstance().setAcceptableDirections(...);

... when the app is launched, with restricted parameters such as :

Display.DIRECTION_NORTH

... and then to call it again at some point later on with the parameters that are actually desired, such as :

Display.DIRECTION_NORTH|Display.DIRECTION_WEST|Display.DIRECTION_EAST

I assume this is meant to somehow reset or kick start the accelerometer bindings to the app.

But the above workaround doesn't seem to be working for us (it's unclear where the setAcceptableDirections(...) calls are to be made, for one), and we're still stuck with the issue of the AccelerometerListener not being called the first time.

Has anyone successfully resolved this?