Skip to main content
Participant
October 25, 2013
Question

What is the method for folder-browsing and selecting a non media file type in Android? [Air+AS3]

  • October 25, 2013
  • 1 reply
  • 2164 views

Dear Gurus,

Being a newbie, I have been searching hi & low for the method to browse and select non-media related file type in android.

Besides the following these which I have reference from the AS3 Documentation (http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7fe4.html#WS5b3ccc516d4fbf351e63e3d118676a4c56-7ff0)

var fileToOpen = File.documentsDirectory.resolvePath("");

                              selectFile(fileToOpen);

                              function selectFile(root:File):void

                              {

                                             //var txtFilter:FileFilter = new FileFilter ("3D Model File", "*.obj; *.3ds;*.awd");

                                             root.browseForOpen("Open",null);

                                             root.addEventListener(Event.SELECT, selectedFile);

                              }

                              function selectedFile(e:Event):void

                              {

                                             trace(fileToOpen.nativePath + " file selected");

                              }

I have went through the following threads yet find no clear workable solution to it.  The closest reference is written in Flex MXML, and I have no luck for converting it to AS3 as there are several properties which I can't get it right.

http://forums.adobe.com/thread/943887 | http://forums.adobe.com/message/4107990#4107990 | http://forums.adobe.com/message/4548154

Someone did mention some possible solutions through ANE but it is just too far beyond.  Even, the closest on-the-shelf solution of ANE by http://myappsnippet.com/file-browser-air-extension/ only work best to an extent and not truely "native" as the UI is not default from Android.  It has workable I/O but poor usability; you can't skin it.

Is there any other workaround solution to this general I/O question?  I would love to hear from everyone here.

This topic has been closed for replies.

1 reply

sinious
Legend
October 28, 2013

The short answer to my knowledge is there is nothing you can invoke from AIR to open an OS-level dialog to browse/select a file. All implementations typically are people writing their own browser. They crawl the folders/files recursively and write their own display for the files. You can see a few on SO:

http://stackoverflow.com/questions/12255418/as3-air-browse-for-file-on-sd-card

http://stackoverflow.com/questions/12257626/as3-get-zip-file-on-phone-from-app-file-path-then-unzip

It's not to terribly hard to code something like this (especially with that starter code). Otherwise, like you found, an on-the-shelf ANE is the only way I believe you can invoke the Android Intent for a file dialog. At that point skinning won't really be terribly easy given the nature of Android users who are completely allowed to customize their UI top to bottom.

The safest bet is just let that posted code recurse and find the files you tell it to while displaying the list to the user. You can use some pre-written GPU-level lists that you can skin yourself using FeathersUI:

http://www.feathersui.com (uses Starling)

Or you can use one of the Flash Pro List components which will be quite a bit slower being they're not GPU optimized like some Flex Spark components.