首次方向更改时未通知 BlackBerry Storm AccelerometerListener
这现在似乎是一个众所周知的问题,但公认的解决方法似乎对我们不起作用。
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论