首次方向更改时未通知 BlackBerry Storm AccelerometerListener

发布于 2024-08-05 04:07:02 字数 1481 浏览 4 评论 0原文

这现在似乎是一个众所周知的问题,但公认的解决方法似乎对我们不起作用。

在 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 不被称为 AccelerometerListener 的问题第一次。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文