- 獲取設備信息 (主要有 :獲取ip地址, 獲取MAC地址 ,獲取IMEI號,獲取手機型號,獲取系統版本,獲取系統API版本,獲取設備 ID )這寫具體的看代碼吧! 直接可以copy 使用的。
public class DeviceUtils {
/**
*
* <pre>
* 獲取ip地址
* </pre>
*
* @return
*/
public static String getIpAddress() {
String ipaddress = "";
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 = ipaddress + ";" + inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
}
return ipaddress;
}
/**
*
* <pre>
* 獲取MAC地址
* </pre>
*
* @param context
* @return
*/
public static String getMacAddress(Context context) {
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
/**
*
* <pre>
* 獲取IMEI號
* </pre>
*
* @param context
* @return
*/
public static String getIMEI(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
return imei;
}
/**
*
* <pre>
* 獲取手機型號
* </pre>
*
* @param context
* @return
*/
public static String getMobleInfo() {
return android.os.Build.MODEL;
}
/**
*
* <pre>
* 獲取系統版本
* </pre>
*
* @param context
* @return
*/
public static String getSystemVersion() {
return android.os.Build.VERSION.RELEASE;
}
/**
*
* <pre>
* 獲取系統API版本
* </pre>
*
* @param context
* @return
*/
public static int getApiVersion() {
return android.os.Build.VERSION.SDK_INT;
}
/**
* 獲取設備 ID
* getDeviceId:(這裏用一句話描述這個方法的作用). <br/>
* @author chenhao
* @param context
* @return
* @since JDK 1.6
*/
public static String getDeviceId(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String DEVICE_ID = tm.getDeviceId();
return DEVICE_ID;
}
}
歡迎大家共同學習交流。與君共勉。
喜歡的可以關注微信公衆號,哪裏每天都會推薦一篇開源項目Git項目地址在裏歡迎訂閱