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
New Contributor
ektorp
Posts: 7
Registered: ‎01-13-2011
My Device: Not Specified

check for an internet connection

Is there a known way to check for an internet connection? My app uses an external web service to load data into my app. If on wifi everything works great...but if there is no wifi or internet connection, it just fails. Is there a way to test for a connection? I'm concerned this will be used against me in the app approval process. Any help would be greatly appreciated.

Developer
thesmileman
Posts: 345
Registered: ‎03-13-2011
My Device: Playbook

Re: check for an internet connection

[ Edited ]

How about URLMonitor and SocketMonitor? You can find out more here:

 

http://www.davidtucker.net/2007/12/15/air-tip-1-%E2%80%93-monitoring-your-internet-connection/

New Developer
bdeneau
Posts: 34
Registered: ‎03-23-2011
My Device: Bold 9700

Re: check for an internet connection

I had that same issue.  Here's how I did it. This will even tell you what your IP is.

 

 

Imports:

 

import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.Socket;

 

Socket Sonnection:

var socket:Socket = new Socket();
socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
socket.addEventListener(Event.CONNECT, socketConnect);
socket.connect("google.com", 80);

 

 

Connection Events:

private function socketConnect(event:Event):void
{
	ip = event.target.localAddress;
	connected = true;
}
		
private function socketError(error:IOErrorEvent):void
{
	trace(error.text);
}