Monitor the availabilty of Internet Connection for an AIR application

23Nov09

The beauty of Adobe AIR is it enables to develop and deploy a Rich Internet Application (RIA) on the desktop. But one interesting scenario which develops when deploying a RIA on the desktop is, how will the application know, if the internet connection is currently available? How to enable run time handling of the application based on the availability of the Internet Connection?

AIR SDK answers all this by providing the developer with the URLMonitor Class. This class which is included in the ServiceMonitor.swc file, provides properties and methods to handle changes in the Internet Connection. The following steps explain, how to make efficient use of the URLMonitor class to check the availability of the Internet Connection.

Step 1: To access the properties and methods of the URLMonitor class we will have to import the air.net.URLMonitor class

import air.net.URLMonitor;

Step 2: Create an object of URLMonitor class.

private var monitor:URLMonitor;

Step 3: Create an URLRequest object and to the constructor pass the URL you wish to be requested

private var myURL:URLRequest = new URLRequest(“http://www.adobe.com”);

Step 4: On Creation Complete of the application, instantiate the URLMonitor object (monitor) by passing the URLRequest object (myURL) as one of the parameters

monitor = new URLMonitor(myURL);

Step 5: Start the URLMonitor by calling the method start()

monitor.start();

Step 6: Add an event listener where the event is of type Status. This indicates that the service status has changed.

monitor.addEventListener(StatusEvent.STATUS, on_Connection);

Step 7: Now the last and the final step. In the filter function on_Connection(event:Event), check if the Internet Connection is available by checking the boolean value of the property “available”.

protected function on_Connection(event:Event):void
{
if(event.target.available == true)
{
//Code comes here
}
}
So in 7 simple steps, we have devised a solution to check for the availability of the Internet Connection in an AIR application.
Code snippet available below,
protected function on_Connection(event:Event):void 			{ 				if(event.target.available == true) 				{

Advertisement


No Responses Yet to “Monitor the availabilty of Internet Connection for an AIR application”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.