BlackBerry Storm AccelerometerListener在第一次方向更改时未收到通知

时间:2009-09-17 02:25:01

标签: blackberry accelerometer blackberry-storm rim-4.7

这似乎是一个众所周知的问题,但是接受的解决方案似乎对我们没有用。

在BlackBerry Storm(JDE 4.7,标准的4.7+模拟器)上,以下代码注册了 AccelerometerListener 。监听器不会在设备方向的第一次更改时被调用,但会在每次后续的方向更改时调用。

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.
}

使用上面的代码,以纵向模式启动应用程序,然后翻转设备(或进行任何其他方向更改)应强制加速度计调用侦听器的 onData()。这确实发生了,但仅限于设备的第二次和随后的翻转。始终忽略第一个方向更改。

网上流传的解决方案似乎是强行召唤:

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

...启动应用时,使用受限制的参数,例如:

Display.DIRECTION_NORTH 

...然后稍后再使用实际需要的参数再次调用它,例如:

Display.DIRECTION_NORTH|Display.DIRECTION_WEST|Display.DIRECTION_EAST

我认为这意味着以某种方式重置或启动加速度计绑定到应用程序。

但是上面的解决方法对我们来说似乎没有用(我不清楚setAcceptableDirections(...)调用的位置,对于一个),我们仍然坚持使用AccelerometerListener的问题而不是被称为第一次。

有没有人成功解决了这个问题?

0 个答案:

没有答案