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
Regular Contributor
fancyoso
Posts: 63
Registered: ‎01-25-2011
Accepted Solution

checking for WiFi

hi,

 

how can i find out, if a wifi-connection is available?
my app only works with internet and i want to throw a message right at the start, because otherwise it would only look broken.

i was very surprised that i couldn't find anything on this board, because the problem seems pretty basic

 

thanks

Please use plain text.
New Contributor
dhamu_tg
Posts: 2
Registered: ‎04-23-2010
My Carrier: apps

Re: checking for WiFi

you can try the below code snippet to check the wifi is avilable or not

 

private boolean isWifiAvilable()
 {
  ConnectionFactory connectionFactory = new ConnectionFactory();
  int[] types =
  {
   TransportInfo.TRANSPORT_TCP_WIFI,
  };
  connectionFactory.setPreferredTransportTypes(types);
  connectionFactory.setAttemptsLimit(1);
  connectionFactory.setConnectionTimeout(1000);
  
  ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(url, TransportInfo.TRANSPORT_TCP_WIFI, null);

  if (connectionDescriptor != null)
  {
   return true;
  }
  
  return false;
 }
 
 http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/io/transport/ConnectionFactory...

Please use plain text.
Regular Contributor
fancyoso
Posts: 63
Registered: ‎01-25-2011

Re: checking for WiFi

thanks for your quick answer.

 

but that isn't actionscript(!?)

 

i can't create a connectionfactory object

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: checking for WiFi

ConnectionFactory is Java. One way is try to URLLoader to a well known web addresss and capture the response and error to determine if you have an internet connection. You can also monitor a host, but that does a similiar thing.
Please use plain text.
Developer
UberschallSamsara
Posts: 838
Registered: ‎12-29-2010

Re: checking for WiFi

Please use plain text.
Regular Contributor
fancyoso
Posts: 63
Registered: ‎01-25-2011

Re: checking for WiFi

i did it with an url request and it seems to work :smileyhappy:

here is the code:

 

public class WiFiChecker extends EventDispatcher
	{
		public static var _WIFIAVAILABLEEVENT:String = "WIFIAVAILABLE";
		private var _wifiAvailable:Boolean = false;
		private var _timer:Timer = new Timer(1000, 1);
		
		
		public function WiFiChecker()
		{
			var request:URLRequest  = new URLRequest("http://www.google.com");
			var loader:URLLoader = new URLLoader(request);
			loader.addEventListener(Event.COMPLETE, doneLoading);
			loader.load(request);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerRanOut); 
		}
		
		private function timerRanOut(e:Event):void{
			trace("WiFi Ping-TimeOut");
			this.dispatchEvent(new Event(_WIFIAVAILABLEEVENT));
		}
		
		public function wifiIsAvailable():Boolean{
			return _wifiAvailable;
		}
		
		private function doneLoading(e:Event):void{
			_wifiAvailable = true;
			this.dispatchEvent(new Event(_WIFIAVAILABLEEVENT));
		}  
	}

 

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: checking for WiFi

I would listen to IOErrorEvent as well. You might get a callback from that before your timer times out.
Please use plain text.
New Contributor
victor_itelecom
Posts: 3
Registered: ‎09-10-2012
My Carrier: Movistar

Re: checking for WiFi

Along with greeting I ask help to develop a product on the platform RIM-OS specifically on Wifi API.

I wonder if  can by API level (code)  manage wireless networks?

can we change the priority setting too?.

How to create WIFI profiles  from code and you can connect / disconnect from a WiFi network?.

And finally, if you can manage networks profiles like EAP / AKA - EAP / SIM from code?.

If exists a way to do it, can you explained to us?

For this I suggest if you can guide me on where and how to do it, or if there is some kind of commercial support for companies (paid) on the use of these APIs.

Thank you for your cooperation and we are in contact.

Please use plain text.
Developer
jtegen
Posts: 6,529
Registered: ‎10-27-2010
My Carrier: Verizon

Re: checking for WiFi

What development environment are you trying to do this in?
In AIR, this is not currently possible unless it is available in the NDK via an ANE. I would ask/check in the NDK forum for these specifics.
Please use plain text.