For file association management, the flash.desktop.NativeApplication class in AIR provides 4 methods:
isSetAsDefaultApplication(extension:String):Boolean returns whether the current AIR application is the default way to open the specified file format. The extension parameter is a file extension string — you don’t write the “.”, for example “flv”. The extension for the next 3 is the same.
setAsDefaultApplication(extension:String):void associates the current application with a certain file format.
removeAsDefaultApplication(extension:String):void removes the association between an AIR application and a file.
getDefaultApplication(extension:String):String reports the path of the application associated with a certain file. Returns a string of the application path.
File associations must be declared in the application descriptor file. When an AIR application is installed, the runtime automatically associates the corresponding files, setting the default way to open files of that format to your AIR application. However, because the AIR installer doesn’t overwrite any file associations, file formats that already have another program set as the default are left untouched. A good habit to get into: at application startup, verify the file formats you want to associate — that is, verify whether the default opening method has been set to that AIR application. After all, AIR applications don’t overwrite existing file associations, and other applications may modify your file association. If you run into another installer that has associated a file you need to associate, you can use setAsDefaultApplication() to set the association, but it’s best to get the user’s consent first. Note that AIR only allows you to manage file associations for extensions declared in the application descriptor file, so we can’t get association info for undeclared file types, and any operation on an undeclared extension will cause an application exception to be thrown. The element structure for declaring file associations in the application descriptor file is as follows: <fileTypes> <fileType> <name>adobe.VideoFile</name> <extension>avf</extension> <description>Adobe Video File</description> <contentType>application/vnd.adobe.video-file</contentType> <icon> <image16×16>icons/AIRApp_16.png</image16×16> <image32×32>icons/AIRApp_32.png</image32×32> <image48×48>icons/AIRApp_48.png</image48×48> <image128×128>icons/AIRApp_128.png</image128×128> </icon> </fileType> </fileTypes>
For more on the application descriptor file, see this article — AIR Application Descriptor File in Detail.
[09.08.31 update] Xiaoxin: the example above is already quite clear, so here’s another official AIR example:
com.adobe.flv
flv
Video for Flash
video/x-flv
/assets/icons/flv_icon_16.png
/assets/icons/flv_icon_32.png
/assets/icons/flv_icon_48.png
/assets/icons/flv_icon_128.png
com.adobe.f4v
f4v
MPEG-4 Video for Flash
video/x-f4v
/assets/icons/f4v_icon_16.png
/assets/icons/f4v_icon_32.png
/assets/icons/f4v_icon_48.png
/assets/icons/f4v_icon_128.png