Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 31
Registered: ‎12-25-2010
My Device: PlayBook
My Carrier: Rogers
Accepted Solution

API call to figure out if an Internet connection is available?

Is there some API call in either AIR or the Playbook's libraries with which I can determine if a live internet connection is available? I would like to know when the user is on any of Wifi/3G/4G (i.e. any type of connectivity) so my app can try to request data online instead of using the local cache.

 

Thanks!

_________________
My apps: PlayText
Highlighted
Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A

Re: API call to figure out if an Internet connection is available?

[ Edited ]

you can use the ServiceMonitor class to check for an internet connection.

 

first, you have to explicitly link against the "aircore.swc" located in the AIR SDK.  from the documentation:

 

To use air.net package in Adobe® Flash® Professional (CS4 or higher):

1.  Select the File > Publish Settings command.
2.  In the Flash panel, click the Settings button for ActionScript 3.0. Select Library Path.
3.  Click the Browse to SWC File button. Browse to Adobe Flash CSn/AIKn.n/frameworks/libs/air/aircore.swc file in the Adobe Flash Professional installation folder.
4.  Click the OK button.

after that, you can test for a network connection by writing something like the following working example (document class):

 

package
{
import air.net.URLMonitor;
import flash.display.Sprite;
import flash.events.StatusEvent;
import flash.net.URLRequest;
 
public class NetworkTest extends Sprite
	{
	public function NetworkTest()
		{
		var monitor:URLMonitor;
		monitor = new URLMonitor(new URLRequest("http://www.google.com"));
		monitor.addEventListener(StatusEvent.STATUS, statusEventHandler);
		monitor.start();		
		}

	private function statusEventHandler(evt:StatusEvent):void
		{
		trace("Network Connection: " + evt.code);
		}
	}
}

 

 


PlayBook Applications:
Drop Swatch
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: API call to figure out if an Internet connection is available?

 


alinium wrote:

Is there some API call in either AIR or the Playbook's libraries with which I can determine if a live internet connection is available? 


There are a few pages out there with examples:

 

air.net.URLMonitor: http://livedocs.adobe.com/flex/3/html/help.html?content=network_connectivity_1.html

 

video tutorial using the above API call:  http://tv.adobe.com/watch/adc-presents/detecting-network-connectivity-in-your-adobe-air-application/

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators