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

问题描述 投票:-2回答:2

我尝试使用谷歌搜索,但我发现的只是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 + "\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并在我的设备上运行它。什么都没有,只有白色。

android actionscript-3 air
2个回答
1
投票

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


1
投票

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

Tutorial for WifiTags

© www.soinside.com 2019 - 2024. All rights reserved.