---
title: "Android 获取当前设备的IP地址"
author: "fonter"
date: "2010-05-19T14:58:54Z"
tags: []
categories: ["移动开发"]
slug: "android-ip"
draft: false
lastmod: "2010-05-19T14:59:45Z"
id: 669872
url: "https://fonter.iteye.com/blog/669872"
---

获取当前设备的IP地址

 

```
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);   
WifiInfo wifiInfo = wifiManager.getConnectionInfo();   
int ipAddress = wifiInfo.getIpAddress();   
String ip = intToIp(ipAddress);   
  
public String intToIp(int i) {   
  
   return ((i >> 24 ) & 0xFF ) + "." +   
               ((i >> 16 ) & 0xFF) + "." +   
               ((i >> 8 ) & 0xFF) + "." +   
               ( i & 0xFF) ;   
}  
```