【问题标题】:How do get a list of available networks on Android AIR?如何获取 Android AIR 上的可用网络列表?
【发布时间】:2016-02-10 23:05:23
【问题描述】:

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

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

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

/*

ADOBE 系统公司 版权所有 2011 Adob​​e Systems Incorporated 版权所有。

注意:Adobe 允许您根据以下规定使用、修改和分发此文件 随附的 Adob​​e 许可协议的条款。如果您从 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 并在我的设备上运行它时。什么都没有出现,只有白色。

【问题讨论】:

  • NetworkInfo 正是这样做的,你为什么不解释一下你想做什么呢。
  • 您正在寻找可用 WiFi 网络的列表? ANE 可能会这样做,但您到底想做什么?
  • 使用 networkInfo 给了我这个错误。无法访问空对象引用的属性或方法。
  • NetworkInfo 不会那样做,你写的一些代码会那样做;显示引发该错误的代码。
  • 我已经用更多细节更新了这个问题。

标签: android actionscript-3 air


【解决方案1】:

NetworkInfo 并非在所有移动设备上均受支持。轮询 isSupported 标志以查看您是否有权访问。如果这样做,只需调用 findInterfaces() 即可检索和数组 NetworkInterface 对象。

【讨论】:

    【解决方案2】:

    我发现另一个很棒的 ANE 可以完美地工作。它被称为“WifiTags”。它适用于 Windows 和 Android。感谢所有回答的人。

    Tutorial for WifiTags

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 1970-01-01
      相关资源
      最近更新 更多