Detecting External Storage Devices with Adobe AIR, HTML and JavaScript - The StorageVolumeChangeEvent

Filed under: AIR, JavaScript

comments (5) Views: 6,928

Phillip Senn over on the AIR with HTML and JavaScript Google Group recently asked "How to use the StorageVolumeChangeEvent". Instead of just handing over a few lines of code, or pointing him to the documentation, I thought I'd take some time and write up an AIR project that you can download and use as reference. The ability to detect external storage devices is a feature released in AIR 2.0, and this article will show you how to utilize it in your applications. Download the full source code, then import the project into ColdFusion Builder, or Aptana. Since the code is fairly short, let's look at the whole thing, then I'll call out specifics.

When you run this app, you should see something like this:

While the application is running, insert any writeable external storage device, such as a thumb drive, or external hard drive, and you should see something like this:

What allows us to snoop into the file system of the hard drive? It's the StorageVolumeChangeEvent event found in the StorageVolumeInfo class. That's shorthand for saying AIR allows us to be notified when someone plugs in a USB stick, and we can then go digging into the file system to display it's contents. Lets highlight the important parts.

These lines of code are where the magic happens. All you need to do is listen for the correct event, then when it's announced, you can act upon it. The StorageVolumeChangeEvent carries along with it all the information about the announced device that you'll need to determine the name, remaining disk space, it's system path, and even the contents of the drive itself.

I hope this shows you just how easy it is to develop AIR applications with JavaScript that offer advanced functionality. As always, stay tuned for more.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s