01-11-2011 05:59 AM
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!
Solved! Go to Solution.
01-11-2011 07:28 AM - edited 01-11-2011 08:02 AM
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);
}
}
}
01-11-2011 07:33 AM
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?co
video tutorial using the above API call: http://tv.adobe.com/watch/adc-presents/detecting-n