Adobe Air - 检测连接是否为WIFI,3G或EDGE

时间:2012-03-26 12:43:50

标签: actionscript-3 flex air flex4

我需要确定设备使用的连接类型。 在iOS(使用NetworkInfo ANE)和Android(使用原生NetworkInfo类)上区分WIFI和3G似乎不是问题,但我不知道如何进一步区分快速(3G, 4G)和慢速(EDGE)连接。 有没有办法用Adobe Air做到这一点?

3 个答案:

答案 0 :(得分:13)

尝试使用此功能检测iOS上的移动与Wifi。这需要Adobe原生扩展“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 );

答案 1 :(得分:0)

我不知道如果有解决方案是直接解决方案,但是当你下载文件时,你可以通过使用getTimer函数和加载的字节以及总字节比来检查文件下载的速度。

实施例

function init()
{
    startTime = getTimer();
    loader = new Loader();
    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderInit);
    loader.load("some-site.com/myasset.png");
}

function onLoaderInit(e:ProgressEvent)
{
    $timePassed = (getTimer() - startTime) * 0.001; //it's in millisecounds convert to secounds
    $newBytes = loader.contentLoaderInfo.bytesLoaded - oldBytes; 
    var $rate:Number = $newBytes * $timePassed; //returns a value of bytes per sec.
    startTime = getTimer();
    oldBytes = loader.contentLoaderInfo.bytesLoaded;    
}

答案 2 :(得分:0)

很好......如果它有效... dunno如果有解决方案直接解决方案但是当你下载文件时你可以通过使用getTimer函数和加载的字节来检查下载文件的速度总字节数比率