We are building cross-platform mobile ArcGIS Online apps in Mobile Flex. Much of our early development was done testing on Android, this was mostly due to the restrictions on iOS (provisioning files and UUID’s). One key part of a number of the apps we have built is testing for Internet access. It was no great surprise that the code needed is different between platforms; again iOS presents the greatest challenge. For Android the following will suffice:
[Bindable]
private var interfaces : ArrayCollection = new ArrayCollection();
interfaces.removeAll();
//Check if online/offline for android
for each ( var ni : NetworkInterface in NetworkInfo.networkInfo.findInterfaces() )
{
interfaces.addItem( ni );
}
interfaces.enableAutoUpdate();*/
//If online do something
if(interfaces[0].active)
{
}
For iOS native extensions are required described in the following articles:
http://cookbooks.adobe.com/post_Getting_NetworkInfo_from_both_Android_and_iOS-19473.html”
http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html
One approach which works well for both is as follows:
/// SOLUTION FOR CHECKING FOR INTERNET CONNECTION FOR BOTH IOS AND ANDROID ////
onlineoffline = true;
var testURL:String = “http://www.google.com”;
var testRequest:URLRequest = new URLRequest(testURL);
var urlCheck:URLMonitor = new URLMonitor(testRequest);
urlCheck.addEventListener(StatusEvent.STATUS, statusChanged);
urlCheck.start();
// This function is called when internet connection status has changed
function statusChanged(event:StatusEvent):void
{
trace(“my status is: “+urlCheck.available);
if(urlCheck.available)
{
trace(“You have an internet connection, all is good”);
onlineoffline = true;
}
else
{
trace(“You have no internet connection”);
onlineoffline = false;
}
}
// END OF SOLUTION FOR INTERNET CONNECTION TEST //
Recent Comments