How can I get FilePicker working properly on certain BlackBerry handsets?

老子叫甜甜 提交于 2020-01-07 04:58:11

问题


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?


回答1:


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.




回答2:


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");
                 }
            });
        }


来源:https://stackoverflow.com/questions/7991716/how-can-i-get-filepicker-working-properly-on-certain-blackberry-handsets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!