获取手机id,并以10.0.1.0的形式返回的方法

/**

* 获取手机端的ip

* @return

*/

public static String getIp()

{

WifiManager wifiMgr = (WifiManager) application.getGlobeContext()

.getSystemService(Context.WIFI_SERVICE);

if (isWifiEnabled())

{

int ipAsInt = wifiMgr.getConnectionInfo().getIpAddress();

if (ipAsInt == 0)

{

return null;

} else

{

return intToInet(ipAsInt).getHostAddress();

}

} else

{

return null;

}

}


/**

* 是否Wifi可用

* @return

*/

public static boolean isWifiEnabled()

{

WifiManager wifiMgr = (WifiManager) Xs8_Application.getGlobalContext()

.getSystemService(Context.WIFI_SERVICE);

if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED)

{

ConnectivityManager connManager = (ConnectivityManager) Xs8_Application

.getGlobeContext().getSystemService(

Context.CONNECTIVITY_SERVICE);

NetworkInfo wifiInfo = connManager

.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

return wifiInfo.isConnected();

} else

{

return false;

}

}


public static byte byteOfInt(int value, int which)

{

int shift = which * 8;

return (byte) (value >> shift);

}


public static InetAddress intToInet(int value)

{

byte[] bytes = new byte[4];

for (int i = 0; i < 4; i++)

{

bytes[i] = byteOfInt(value, i);

}

try

{

return InetAddress.getByAddress(bytes);

} catch (Exception e)

{

// This only happens if the byte array has a bad length

return null;

}

}


你可能感兴趣的:(获取手机id,并以10.0.1.0的形式返回的方法)