刚上手Native.js 请教问题如下:
想通过Native.js 获取Android有线网络IP地址,提示这一行console.log(en.hasMoreElements());报错:
Uncaught TypeError: undefined is not a function
/*获取有线网络IP*/
function getLocalIp() {
var ip = "127.0.0.1";
if (plus.os.name == "Android") {
var Enumeration = plus.android.importClass("java.util.Enumeration");
var NetworkInterface = plus.android.importClass("java.net.NetworkInterface");
var en = NetworkInterface.getNetworkInterfaces();
console.log(en.hasMoreElements());
while (en.hasMoreElements()) {
var ni = en.nextElement();
var interfaceName = ni.getDisplayName();
console.log("tag", "网络名字" + interfaceName);
}
/* Android实现
// 获取本地设备的所有网络接口
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
String interfaceName = ni.getDisplayName();
Log.i("tag", "网络名字" interfaceName);
1 个回复
3***@qq.com
我这样调用的,没有报错