Monitoring System Volume changes with Adobe AIR
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.






[...] Monitoring System Volume changes with Adobe AIR (from Mike Chambers) [...]
Flex Monkey Patches » Blog Archive » Rubbernecker’s Review - Week 28 - (Adobe Flex/Flash/AIR/LCDS Blog post recap)
24 Feb 09 at 3:05 pm
Is it easy to use in a JS / HTML enviourment to?
John
25 Feb 09 at 8:24 am
[...] > Monitoring System Volume changes with Adobe AIR at Mike Chambers [...]
localToGlobal » Blog Archive » news review -> 9th week of 2009
3 Mar 09 at 1:03 pm
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
Hi Mike,
Can you maybe place your slides from the FITC online?
Thanks,
Sidney
Sidney de Koning
13 Mar 09 at 3:53 am
[...] 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 [...]
Print Screen detection in AIR | Psyked
17 Apr 09 at 1:24 am
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