Skip to main content
June 9, 2011
Question

Android File Structure/ Opening/ closing files

  • June 9, 2011
  • 1 reply
  • 1999 views

Hello,

I was wondering if anyone can provide help?

I would like to be able to open and read document files such as PDFs. I am building a simple app in Flash Builder 4.5 that can read a variety of files. I am testing on an Android Device that has a PDF reader installed, I also have some code that checks if a reader is available, but am a little weak at the mo on directory structure.

If I copy a PDF to a newly created folder on the device, eg 'MyDocs' in Storage would the path be \storage\MyDocs ?, how would i reference this.

Any help with how to open files on Android and also a guide on file/ folder structure on a Android device. As I am a little lost how to find this out. Any code/ traces I can run to work this one out would be awesome, as would any help ofcourse

Many Thanks

This topic has been closed for replies.

1 reply

Participating Frequently
June 9, 2011

Generally it is recommended to use the File resolvePath() method along with the directory shortcuts. Then you don't have to worry about the file system structure very much.

For example:

//The directory you save files in

var dir:File = File.applicationStorageDirectory.resolvePath("saved_file_dir");

//A pdf in that directory

var pdf1:File = dir.resolvePath("savedPDF");

You can then use the url property (i.e. "pdf1.url") to reference the file in methods that need a url.

June 10, 2011

Joe,

Many thanks for your response. I would like to try your suggestion but need a little clarification if possible.

So trying your code as follows doesnt seem to work for me, i am not sure why at the moment, any ideas:

/*************************************************load file*****************************************************/

var mainStore:File = File.applicationStorageDirectory;

var mainPath:String = mainStore.nativePath;

var appDir:File = File.applicationStorageDirectory.resolvePath(mainPath);

//in my FB project, in the bin folder I have an 'assets folder where the PDF is placed

var dirFolder:File = appDir.resolvePath("assets");

var pathTrace:String = dirFolder.nativePath.toString()

trace(pathTrace);

trace(dirFolder.url + "/view.pdf");

webView.loadURL( dirFolder.url + "/view.pdf" );

/***************************************************************************************************************/

when I run the app on the android device i get the following error in webview

webpage not available

web page at file:///data.data.air.myApp.debug/myApp.debug/Local%20Store/assets/view.pdf not available

run in emulator i get error:

Error #2044: Unhandled ErrorEvent:. text=[-1] The web page contains an error.: file:///data/data/air.myApp.debug/myApp.debug/Local%20Store/assets/view.pdf

my application name/id = myApp

Any advice greatly appreciated.

Thanks

D

June 10, 2011

also tried:

var appDir:File = File.applicationStorageDirectory.resolvePath("assets");

var myPDF:File = appDir.resolvePath("view.pdf");

webView.loadURL( myPDF.url )

then I get web page error: app-storage:/assets/view.pdf not available

Thanks