Mike Chambers

code = joy

Monitoring System Volume changes with Adobe AIR

with 10 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 ,

10 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

  8. Hi Mike

    Fantastic stuff, works great, I am going to assume you are using a timer and browsing the file system for changes here?

    I am currently using this to check a network drive is mounted on a local users machine, is there any way to connect directly to auto mount a network drive via a network path eg.. smb://example/, I had a play with it though the file object gave a bit of a grunt when adding anything similar to SMB etc…

    Let me know

    Thanks

    Tyrone

    Tyrone Neill

    11 Aug 10 at 12:53 am

  9. @tyroneneil

    Check and see if the path is exposed via the file system somehow. i.e. if it is mounted as a drive or volume? If so, then you can access it via that path…

    Hope that helps…

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Aug 10 at 7:42 am

  10. Hi Mike

    Thanks for the reply.

    I have used parts of your library to check to see if a network drive is mounted and this serves the purpose perfectly.

    I’m more thinking about if the drive is not mounted (this is a large network infrastructure supporting thousands of people) would it be a possibility to auto mount this knowing what the SMB address is? I have a feeling there would be security sandbox issue though would like confirmation?

    Thanks

    Tyrone

    Tyrone Neill

    13 Aug 10 at 1:41 am

Leave a Reply