这里为大家记录一下在uni-app中获取android的当前IP:
let Context = plus.android.importClass('android.content.Context')
let main = plus.android.runtimeMainActivity()
let cm = main.getSystemService(Context.CONNECTIVITY_SERVICE)
plus.android.importClass(cm)
let linkProperties = cm.getLinkProperties(cm.getActiveNetwork())
let linkAddrs = plus.android.invoke(linkProperties, 'getLinkAddresses')
plus.android.importClass(linkAddrs)
for (var i = 0; i < linkAddrs.size(); i++) {
let inetAddr = plus.android.invoke(linkAddrs.get(i), 'getAddress')
let ip = plus.android.invoke(inetAddr, 'getHostAddress')
console.log(ip)
}