O'Reilly logo

Developing Android Applications with Flex 4.5 by Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Working with the File System

AIR on Android provides access to the file system to read, write, and update files of all types. This functionality can be very useful not only for reading existing files, but also for storing files, media, data, and so on. This chapter will demonstrate how to read and write text files, browse the file system for media files, and create and write to an SQLite database.

This chapter has sample applications that require access to the file system, so you will need to select the WRITE_EXTERNAL_STORAGE permission when you are creating these projects. See Chapter 3 for help with permissions.

File System Access

Just as in the desktop version of Adobe AIR, AIR on Android gives you access to the file system. The usage is exactly the same.

Folder Aliases

To access the file system, you can navigate using several folder static alias properties of the File class.

Let’s review the code below. On applicationComplete, the application1_applicationCompleteHandler method is called, and the static File properties are read and written to a String variable. This String variable is written to the text property of a TextArea component. Figure 5-1 shows the results. You will notice that many of the aliases return the same value, which is a path to the device’s external storage card:

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" applicationComplete="application1_applicationCompleteHandler(event)"> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required