如何在Android AIR上获取可用网络列表?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Android AIR上获取可用网络列表?相关的知识,希望对你有一定的参考价值。

我尝试使用谷歌搜索,但我发现的只是Adobe和Freshplanets NetworkInfo ANE的NetworkInfo。由于某种原因,NetworkInfo无法正常工作,而且newplanets network-info API无法做到这一点。还有其他方法可以完成这项任务吗?

我从这个使用networkInfo的链接下载了这个例子:[http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/networkinfo.html][1]

以下是上面示例中主类的代码:

/*

ADOBE SYSTEMS INCORPORATED版权所有2011 Adob​​e Systems Incorporated保留所有权利。

注意:Adobe允许您根据随附的Adobe许可协议的条款使用,修改和分发此文件。如果您从Adobe以外的来源收到此文件,则您的使用,修改或分发需要事先获得Adobe的书面许可。

*/

package
{

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

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextField;
import flash.text.TextFormat;

public class NetworkInfoUsageApp extends Sprite
{
    private var info:TextField;
    public function NetworkInfoUsageApp()
    {
        super();    

        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();

        info = makeTextField(50, 50);

        for each (var interfaceObj:NetworkInterface in ntf)
        {
            trace("Interface Name:" + interfaceObj.name + "
" );
            trace("MTU:" + interfaceObj.mtu.toString + "
" );
            trace("Display Name of the Interface:" + interfaceObj.displayName + "
" );
            trace ("Active ?" + interfaceObj.active.toString() + "
" );
            trace("Hardware Address:" + interfaceObj.hardwareAddress + "
");



            info.appendText("Interface Name:" + interfaceObj.name + "
" );
            info.appendText("MTU:" + interfaceObj.mtu.toString() + "
" );
            info.appendText("Display Name of the Interface:" + interfaceObj.displayName + "
" );
            info.appendText("Active ?" + interfaceObj.active.toString()+ "
");
            info.appendText("Hardware Address:" + interfaceObj.hardwareAddress + "
");

            for each(var address:InterfaceAddress in interfaceObj.addresses)
            {
                trace("Address" + address.address + "
");
                trace("broadcast address" + address.broadcast + "
");
                trace("ipversion" + address.ipVersion + "
")
                trace("prefixlength" + address.prefixLength +"
")

                info.appendText("Address" + address.address + "
" );
                info.appendText("broadcast address" + address.broadcast + "
" );
                info.appendText("ipversion" + address.ipVersion + "
");
                info.appendText("prefixlength" + address.prefixLength +"
" );

            }


        }


    }
    private function makeTextField(x:Number, y:Number):TextField
    {
        var tf:TextField = new TextField();

        tf.x = x;
        tf.y = y;
        tf.border=true;
        this.stage.addChild(tf);
        tf.height = 800;
        tf.width = 450;
        tf.type = "input";
        var tff:TextFormat=new TextFormat();
        tff.size=18;

        tff.color=0x0000ff;
        tf.defaultTextFormat=tff;
        tf.setTextFormat(tff);

        tf.text="hello";
        return tf;
    }
}

}

当我从Flash Pro运行电影时,我收到此错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.adobe.nativeExtensions.Networkinfo::NetworkInfo/findInterfaces()[/Users/gangwar/Documents/Adobe Flash Builder 4.5/NetworkInfoActionScriptLibrary/src/com/adobe/nativeExtensions/Networkinfo/NetworkInfo.as:70]
at NetworkInfoUsageApp()[C:UsersDaniDesktopwifi testNetworkInfoUsageAppsrcNetworkInfoUsageApp.as:39]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()

当我发布apk并在我的设备上运行它。什么都没有,只有白色。

答案

并非所有移动设备都支持NetworkInfo。轮询isSupported标志,看看你是否有权访问。如果你这样做,只需将findInterfaces()调用为retreive和NetworkInterface对象数组。

另一答案

我找到了另一个令人敬畏的ANE,它完美无缺。它被称为“WifiTags”。它适用于Windows和android。感谢所有回答的人。

Tutorial for WifiTags

以上是关于如何在Android AIR上获取可用网络列表?的主要内容,如果未能解决你的问题,请参考以下文章

适用于 Android 的 Upnp 本机扩展 - AIR

如何从浏览器获取本地存储在 Android 中的文件列表?

Android:如何获取所有可用网络运营商的 GSM 信号强度

iOS 上的 Flash/AIR 舞台视频 - 有可能吗?表现如何?

iOS8在iPad Air上使用HealthKit时如何修复“此设备上的健康数据不可用”

iOS8在iPad Air上使用HealthKit时如何修复“此设备上的健康数据不可用”