当连接到3G移动网络获取Android设备的IP地址 [英] Getting the IP address of the android device when connected to 3G mobile network

查看:259
本文介绍了当连接到3G移动网络获取Android设备的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我连接到无线网络,我可以得到Android手机的IP地址。

When I am connected to WiFi, I can obtain the IP address of the Android phone.

然而,当移动网络就像3G连接上,它仍然能获得Android手机的IP地址?
如果是的话,请张贴$ C $下是一样的。

However, when on the mobile network like 3G connection, is it still possible to obtain the IP address of the Android phone?
If yes, kindly post the code for the same.

推荐答案

尝试这样的事情

String ipAddress = null;
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    ipAddress = inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (SocketException ex) {}

这篇关于当连接到3G移动网络获取Android设备的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆