How can I get FilePicker working properly on certa

2019-08-23 11:58发布

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?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-23 12:38

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.

查看更多
forever°为你锁心
3楼-- · 2019-08-23 12:58

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");
                 }
            });
        }
查看更多
登录 后发表回答