如何以编程方式获取Android移动设备的IP地址...? [英] How to get the ip address of an android mobile programatically ....?

查看:75
本文介绍了如何以编程方式获取Android移动设备的IP地址...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道android设备通过wifi连接到网络时的确切IP地址!任何人都可以帮助我如何在移动设备连接到网络时获取IP地址以及如何通过编程方式获取地址..

I want exact IP address of android device when it will connected to a network through wifi! can any one help me how to get the ip address while the mobile is connected to a network and how to get the address through pro-grammatically ..

推荐答案

我使用了它,而且效果很好!

I used this and it workd !

WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());

在清单文件中具有权限.

Below permissions in the manifest file.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

这篇关于如何以编程方式获取Android移动设备的IP地址...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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