Working with AIR runtime and operating system information

Adobe AIR 1.0 and later

This section discusses ways that an AIR application can manage operating system file associations, detect user activity, and get information about the Adobe® AIR® runtime.

Managing file associations

Associations between your application and a file type must be declared in the application descriptor. During the installation process, the AIR application installer associates the AIR application as the default opening application for each of the declared file types, unless another application is already the default. The AIR application install process does not override an existing file type association. To take over the association from another application, call the NativeApplication.setAsDefaultApplication() method at run time.

It is a good practice to verify that the expected file associations are in place when your application starts up. This is because the AIR application installer does not override existing file associations, and because file associations on a user’s system can change at any time. When another application has the current file association, it is also a polite practice to ask the user before taking over an existing association.

The following methods of the NativeApplication class let an application manage file associations. Each of the methods takes the file type extension as a parameter:

Method

Description

isSetAsDefaultApplication()

Returns true if the AIR application is currently associated with the specified file type.

setAsDefaultApplication()

Creates the association between the AIR application and the open action of the file type.

removeAsDefaultApplication()

Removes the association between the AIR application and the file type.

getDefaultApplication()

Reports the path of the application that is currently associated with the file type.

AIR can only manage associations for the file types originally declared in the application descriptor. You cannot get information about the associations of a non-declared file type, even if a user has manually created the association between that file type and your application. Calling any of the file association management methods with the extension for a file type not declared in the application descriptor causes the application to throw a runtime exception.

Getting the runtime version and patch level

The NativeApplication object has a runtimeVersion property, which is the version of the runtime in which the application is running (a string, such as "1.0.5" ). The NativeApplication object also has a runtimePatchLevel property, which is the patch level of the runtime (a number, such as 2960). The following code uses these properties:

air.trace(air.NativeApplication.nativeApplication.runtimeVersion); 
air.trace(air.NativeApplication.nativeApplication.runtimePatchLevel);

Detecting AIR capabilities

For a file that is bundled with the Adobe AIR application, the Security.sandboxType property is set to the value defined by the Security.APPLICATION constant. You can load content (which may or may not contain APIs specific to AIR) based on whether a file is in the Adobe AIR security sandbox, as illustrated in the following code:

if (window.runtime) 
{ 
    if (air.Security.sandboxType == air.Security.APPLICATION) 
    {  
        alert("In AIR application security sandbox."); 
    } 
    else 
    { 
        alert("Not in AIR application security sandbox.") 
    } 
} 
else 
{ 
    alert("Not in the Adobe AIR runtime.") 
}

All resources that are not installed with the AIR application are put in security sandboxes based on their domains of origin. For example, content served from www.example.com is put in a security sandbox for that domain.

You can check if the window.runtime property is set toto see if content is executing in the runtime.

For more information, see AIR security .

Tracking user presence

The NativeApplication object dispatches two events that help you detect when a user is actively using a computer. If no mouse or keyboard activity is detected in the interval determined by the NativeApplication.idleThreshold property, the NativeApplication dispatches a userIdle event. When the next keyboard or mouse input occurs, the NativeApplication object dispatches a userPresent event. The idleThreshold interval is measured in seconds and has a default value of 300 (5 minutes). You can also get the number of seconds since the last user input from the NativeApplication.nativeApplication.lastUserInput property.

The following lines of code set the idle threshold to 2 minutes and listen for both the userIdle and userPresent events:

air.NativeApplication.nativeApplication.idleThreshold = 120; 
air.NativeApplication.nativeApplication.addEventListener(air.Event.USER_IDLE, function(event) { 
    air.trace("Idle"); 
}); 
air.NativeApplication.nativeApplication.addEventListener(air.Event.USER_PRESENT, function(event) { 
    air.trace("Present"); 
});
Note: Only a single userIdle event is dispatched between any two userPresent events.

// Ethnio survey code removed