WifiManager wifimanage=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);//获取WifiManager //检查wifi是否开启 if(!wifimanage.isWifiEnabled()) { wifimanage.setWifiEnabled(true); } WifiInfo wifiinfo= wifimanage.getConnectionInfo(); String ip=intToIp(wifiinfo.getIpAddress()); //将获取的int转为真正的ip地址,参考的网上的,修改了下 private String intToIp(int i) { return (i & 0xFF)+ "." + ((i >> 8 ) & 0xFF)? + "." + ((i >> 16 ) & 0xFF) +"."+((i >> 24 ) & 0xFF ); }
OK,这样就好了吗?呵呵,别忘记加上权限 <uses -permission="" android:name="android.permission.ACCESS_WIFI_STATE"></uses> <uses -permission="" android:name="adnroid.permission.CHANGE_WIFI_STATE"></use