0

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?

bharath
  • 14,283
  • 16
  • 57
  • 95
Buffel
  • 45
  • 7
  • are you sure that selectionDone is not called?try with only a Dialog in selectionDone like this: public void selectionDone(String str) { Dialog.alert("Filename: "+str); } check again with this if method is called – frayab Nov 03 '11 at 15:24
  • That is the way I was checking if it gets called. I even just put in a Dialog that popped up with a generic message and that didn't get called. – Buffel Nov 04 '11 at 08:29

2 Answers2

0

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");
                 }
            });
        }
Farid Farhat
  • 2,300
  • 1
  • 16
  • 29
  • Thank you. When I try this, though, the error doesn't get thrown. The FilePicker still pops up. Do you know where I can find a list of the handsets that this issue occurs on? I've got another custom file browser that I can use instead of FilePicker that I can implement on these handsets. Alternately, is there any function that can determine if this issue is present on a particular handset when I run the app so I can just build one version and have it determine by itself which file browser to use? – Buffel Nov 04 '11 at 08:30
  • When an error is thrown, the FilePicker doesn't pop up... So if it pops up there is no error ... Check your logs, press ALT + LGLG to see if an error is thrown – Farid Farhat Nov 04 '11 at 10:05
  • Aha. OK, the log is telling me that it's throwing a ControlledAccessException due to Unauthorized attempt to monitor key presses. I wonder why this exception isn't being caught by my exception handler. Either way, it's definitely not throwing an Error, since the FilePicker still pops up. – Buffel Nov 04 '11 at 10:27
  • Well try to catch this type of exception only – Farid Farhat Nov 04 '11 at 11:07
0

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.

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
  • Thank you. I'll just catch the ControlledAccessException exception and use that to call a custom file browser in those cases. I hope that approach will work. – Buffel Nov 14 '11 at 07:52