如何让 FilePicker 在某些 BlackBerry 手机上正常工作?
我正在我的应用中实现一个Filepicker
,以允许用户从手机中选择照片。我使用的代码如下:
调用 Filepicker:
try
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
FilePicker fp = FilePicker.getInstance();
fileListener = new FilePickListener();
fp.setListener(fileListener);
fp.show();
}
});
}
catch (Exception e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Please check your data card..");
}
});
}
以及在我的 FilePickListener:
中获取文件名的方法
public void selectionDone(String str)
{
this.currFileName = str;
int index = str.lastIndexOf('/');
Dialog.alert("Filename: "+str.substring(index+1).trim());
}
这在我尝试过的大多数手机中都完美运行(其中一些手机运行 OS5,一些运行 OS6)。但在某些设备上,例如 8900(运行操作系统 v5.0.0.411),它无法正常工作。 Filepicker
被调用并出现,但是当选择任何文件时,selectionDone 方法不会被调用。我在两个独立的 8900 上进行了测试,两者都有相同的问题。
有谁知道为什么它适用于某些手机而不适用于其他手机?
I'm implementing a Filepicker
in my app to allow users to choose photos from their phones. The code I'm using is as follows:
Calling the Filepicker:
try
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
FilePicker fp = FilePicker.getInstance();
fileListener = new FilePickListener();
fp.setListener(fileListener);
fp.show();
}
});
}
catch (Exception e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Please check your data card..");
}
});
}
And the method to get the filename in my FilePickListener:
public void selectionDone(String str)
{
this.currFileName = str;
int index = str.lastIndexOf('/');
Dialog.alert("Filename: "+str.substring(index+1).trim());
}
This works perfectly in most handsets that I've tried it on (which have been a mix of handsets with some running OS5 and some running OS6). But on some, like the 8900 (running OS v5.0.0.411) it doesn't work properly. The Filepicker
gets called and appears, but when any file gets selected, the selectionDone method doesn't get called. I've tested it on two separate 8900s and both have the same problem.
Does anyone have an idea why it works on certain handsets and not other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是已知 RIM 问题的受害者:FilePicker 抛出 ControlledAccessException。
该问题被标记为“已修复”。但是没有任何信息表明他们在哪个操作系统版本中修复了该问题。 (这么有用的信息有那么难说吗?)
但是从这个问题的评论来看:
因此我猜测他们会在操作系统 5.0.0.464 中修复它。但这还不是结束 - 在 OS 6
FilePicker
在早期版本的 OS 6 中再次出现故障。结论——只是不要使用它。使用自定义文件浏览器屏幕来选择文件。 SDK 4.7.0中有一个名为FileExplorerDemo的示例,请查看它的实现细节。You are a victim of a known RIM issue: FilePicker throws ControlledAccessException.
The issue is marked as "Fixed". However there is no info in which OS version they fixed it. (Is it so difficult to tell such a useful info?)
But from the comments to the issue:
so my guess would be they fixed it in OS 5.0.0.464. But that's not the end - in OS 6
FilePicker
appears broken in early versions of OS 6 again. The conclusion - just don't use it. Use a custom file browser screen to pick a file. There is a sample in SDK 4.7.0 named FileExplorerDemo, check it for implementation details.这是一个已知问题。 FilePicker 在某些设备上无法打开并返回错误,例如 8900 设备。您可以通过添加
catch (Error e) { }
在某些设备上捕获此错误This is a known issue. FilePicker does not open on some devices and return an error, like the 8900 device. You can catch this error on some devices by adding the
catch (Error e) { }