如何让 FilePicker 在某些 BlackBerry 手机上正常工作?

发布于 2024-12-13 05:32:36 字数 1238 浏览 0 评论 0原文

我正在我的应用中实现一个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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恬淡成诗 2024-12-20 05:32:36

您是已知 RIM 问题的受害者:FilePicker 抛出 ControlledAccessException

该问题被标记为“已修复”。但是没有任何信息表明他们在哪个操作系统版本中修复了该问题。 (这么有用的信息有那么难说吗?)

但是从这个问题的评论来看:

我们在 Bold 9700 上的操作系统 5.0.0.321 上遇到了同样的问题。但是,该问题不会出现在操作系统 5.0.0.464 上

因此我猜测他们会在操作系统 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:

We experience the very same issue with OS 5.0.0.321 on a Bold 9700. However, the issue does NOT appear on OS 5.0.0.464

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.

千笙结 2024-12-20 05:32:36

这是一个已知问题。 FilePicker 在某些设备上无法打开并返回错误,例如 8900 设备。您可以通过添加 catch (Error e) { } 在某些设备上捕获此错误

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..");
                 }
            });
        }
        catch (Error e)
        {
             UiApplication.getUiApplication().invokeLater(new Runnable()
             {
                 public void run()
                 {
                      Dialog.alert("This device does not support File Picker");
                 }
            });
        }

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) { }

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..");
                 }
            });
        }
        catch (Error e)
        {
             UiApplication.getUiApplication().invokeLater(new Runnable()
             {
                 public void run()
                 {
                      Dialog.alert("This device does not support File Picker");
                 }
            });
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文