Mike Chambers

code = joy

Monitoring System Volume changes with Adobe AIR

with 7 comments

I am at FITC Amsterdam this week, where I had a talk on Desktop Development with Adobe AIR. One of the things I showed was how to get notifications when new volumes / drives are added / removed to a machine. This could be useful if for example, you application needs to know when a new CD Rom or USB drive has been added or removed to the user’s system.

Anyways, I create a reusable class called VolumeMonitor that makes it very easy to monitor volume changes. I have checked in the code into the as3corelib library under the AIR package. Its not in the build yet, but once I write some docs and unit tests, and check for some bugs, Ill add it to the next build.

Here is an example of the code in use:

import com.adobe.air.filesystem.events.FileMonitorEvent;
import com.adobe.air.filesystem.VolumeMonitor;

private var monitor:com.adobe.air.filesystem.VolumeMonitor;

private function onApplicationComplete():void
{
	monitor = new com.adobe.air.filesystem.VolumeMonitor();
	monitor.addEventListener(FileMonitorEvent.ADD_VOLUME, onAddVolume);
	monitor.addEventListener(FileMonitorEvent.REMOVE_VOLUME, onRemoveVolume);
	monitor.watch();
}

private function onAddVolume(e:FileMonitorEvent):void
{
	trace("Volume added : " + e.file.url);
}

private function onRemoveVolume(e:FileMonitorEvent):void
{
	trace("Volume removed : " + e.file.url);
}

 

You can check out the class by grabbing the as3corelib source. If you poke around you will notice some other classes that I have added to the air package, but Ill post about those later.

Written by mikechambers

February 24th, 2009 at 2:32 am

Posted in General

Tagged with ,

7 Responses to 'Monitoring System Volume changes with Adobe AIR'

Subscribe to comments with RSS or TrackBack to 'Monitoring System Volume changes with Adobe AIR'.

  1. [...] Monitoring System Volume changes with Adobe AIR (from Mike Chambers) [...]

  2. Is it easy to use in a JS / HTML enviourment to?

    John

    25 Feb 09 at 8:24 am

  3. [...] > Monitoring System Volume changes with Adobe AIR at Mike Chambers [...]

  4. In FileUtil.as, under getRootDirectories() in the if else-statement, for linux,
    v = File(v[0]).resolvePath(”/media”).getDirectoryListing();
    does the trick for most distributions.

    Joris Timmerman

    12 Mar 09 at 2:58 am

  5. Hi Mike,

    Can you maybe place your slides from the FITC online?

    Thanks,

    Sidney

    Sidney de Koning

    13 Mar 09 at 3:53 am

  6. [...] and watch for changes to it.  Mike Chambers’ Volume Monitor class does something similar [link] with watching the local storage drives, so I’ve stolen that idea. I’m not going to go [...]

  7. Hi,

    Works great. Does somebody know if it’s possible to retrieve the UID from the USB device after Volume was added? Building a dedicated login-station. I know it should be possible with some kind of Java-bridging application, but I prefer doing it directly from flash/air.

    Thanks,
    Tije

    Tije

    12 May 09 at 2:32 am

Leave a Reply