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

时间:2016-02-10 23:05:24

标签: android actionscript-3 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许可协议的条款。如果您从a收到此文件 除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 + "\n" );
            trace("MTU:" + interfaceObj.mtu.toString + "\n" );
            trace("Display Name of the Interface:" + interfaceObj.displayName + "\n" );
            trace ("Active ?" + interfaceObj.active.toString() + "\n" );
            trace("Hardware Address:" + interfaceObj.hardwareAddress + "\n");



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

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

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

            }


        }


    }
    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:\Users\Dani\Desktop\wifi test\NetworkInfoUsageApp\src\NetworkInfoUsageApp.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并在我的设备上运行它。什么都没有,只有白色。

2 个答案:

答案 0 :(得分:1)

所有移动设备均不支持

NetworkInfo 。轮询 isSupported 标记以查看您是否有权访问。如果您这样做,只需致电 findInterfaces() 即可检索NetworkInterface个对象。

答案 1 :(得分:1)

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

Tutorial for WifiTags