Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Air - Detect if connection is WIFI, 3G, or EDGE

I need to determine which connection type a device is using. Distinguishing between WIFI and 3G doesn't seem to be a problem on iOS (using the NetworkInfo ANE) and Android (using the native NetworkInfo class) but I've got no clue how to further distinguish between a fast (3G, 4G) and slow (EDGE) connection. Is there a way to do this with Adobe Air?

like image 344
AlBirdie Avatar asked Mar 26 '12 12:03

AlBirdie


1 Answers

Try this for detecting Mobile vs. Wifi on iOS. This requires the Adobe native extension "NetworkInfo"

import com.adobe.nativeExtensions.Networkinfo.InterfaceAddress;
import com.adobe.nativeExtensions.Networkinfo.NetworkInfo;
import com.adobe.nativeExtensions.Networkinfo.NetworkInterface;

var vNetworkInterfaces:Object; 
if (flash.net.NetworkInfo.isSupported) 
{ 
  vNetworkInterfaces = getDefinitionByName('flash.net.NetworkInfo')['networkInfo']['findInterfaces'](); 
  mytrace("fall 1" );
} 
else 
{ 
  vNetworkInterfaces = getDefinitionByName('com.adobe.nativeExtensions.Networkinfo.NetworkInfo')['networkInfo']['findInterfaces']();
  mytrace("fall 2" );
} 

var hasWifi: Boolean = false;
var hasMobile: Boolean = false;

for each (var networkInterface:Object in vNetworkInterfaces) 
{ 
    if ( networkInterface.active && (networkInterface.name == "en0" || networkInterface.name == "en1") ) hasWifi = true;
    if ( networkInterface.active && (networkInterface.name == "pdp_ip0" || networkInterface.name == "pdp_ip1" || networkInterface.name == "pdp_ip2") ) hasMobile = true;

    mytrace( "active: " + networkInterface.active );
    mytrace( "displayName: " + networkInterface.displayName );
    mytrace( "name: " + networkInterface.name );
    mytrace( "hwAddress: " + networkInterface.hardwareAddress );
    mytrace( "--------------------" ); 
} 

mytrace( "has Mobile Internet: " + hasMobile );
mytrace( "has Wifi Internet: " + hasWifi );
like image 162
Franky Boy Avatar answered Oct 15 '22 16:10

Franky Boy