Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
bobbydriscol
Posts: 23
Registered: ‎05-04-2012
My Device: Playbook, 9670, 9800, 9350
Accepted Solution

SD Card Directories

[ Edited ]

Found my errror in the refernce but the issue still exists.

 

For some reason I can get the contents of 'sdcard' which seems to map to 'shared' on the device, but sdcard2 remains empty.

 

Tried the suggested '/accounts/1000/removable/sdcard' path as well and no luck.

 

 

 

 

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.FileListEvent;
    import flash.events.IOErrorEvent;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    
    
    public class SDCardTester extends Sprite
    {
        private var directorieslist:Vector.<File>;
        private var directorycount:uint = 0;

        public function SDCardTester()
        {
            super();
            
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            var sdcard:File =  rootdirectories[0].resolvePath("sdcard");

            requestcontents(sdcard);
        }
            
        public function requestcontents(dir:File = null):void {
            var directory:File = dir;
            
            if (directory.exists) {
                directory.addEventListener(FileListEvent.DIRECTORY_LISTING, directoryListingHandler);
                directory.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
                directory.getDirectoryListingAsync();
            }
        }
        
        
        private function directoryListingHandler(event:FileListEvent):void {
            var files:Array = event.files;
            var file:File;
            for (var i:Number = 0; i < files.length; i++) {
                file = files[i] as File;
                var type:smileyfrustrated:tring = file.type;
                if (type != null)
                    type = type.toLowerCase();
               if (file.isDirectory) {                
                    trace("directory:" + file.name + "\t{"+file.url+"}");
                    directorycount++;
                    this.requestcontents(file);
                } else {
                    trace("file: ["+file.type+"]" + file.url);
                }
            }
            
            if (directorycount > 0) {
                directorycount--;
            }
        }
        
        private function ioerror(e:IOErrorEvent):void {
            trace(e.toString());
        }
    }
}

 

 

Contributor
bobbydriscol
Posts: 23
Registered: ‎05-04-2012
My Device: Playbook, 9670, 9800, 9350

Re: SD Card Directories

Tried
            var sdcard:File =  rootdirectories[0].resolvePath("/accounts/1000/");

 

for the starting location and all sorts of directories and files traced out without issue, but the 'removable/sdcard' directory is empty (and there's definitly files and content on there that I can see using SuperFileManager from the store).

 

Contributor
bobbydriscol
Posts: 23
Registered: ‎05-04-2012
My Device: Playbook, 9670, 9800, 9350

Re: SD Card Directories

Has anyone had success with reading files from an SD card on the Dev Alpha C using AIR? I see that it's possible through other SDK's so it should work with AIR as well.

 

Any sample project code like I've provided that works for you?

Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook

Re: SD Card Directories

[ Edited ]

Check the last post in this thread about issues with the SDCard

Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: SD Card Directories

It's a bug in the current AIR and Qt runtimes. See:

https://www.blackberry.com/jira/browse/BBTEN-1143

 

If you know the name of the folder, you can still access it. For instance, this would work:

 

var files:Array = new File('accounts/1000/removable/sdcard/documents').getDirectoryListing();

 

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Contributor
bobbydriscol
Posts: 23
Registered: ‎05-04-2012
My Device: Playbook, 9670, 9800, 9350

Re: SD Card Directories

Thanks Innovatology that's the work around I needed. I was stuck thinking the SD card wasn't accessible at all but rather just the top level is not reporting. I'll indicate to the users that they should store their files in a sub directory that has a common name.