会思考的大虾的专栏

获取设备信息 (主要有 :获取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;}

}

欢迎大家共同学习交流。与君共勉。

有希望在的地方,痛苦也成欢乐

会思考的大虾的专栏

相关文章:

你感兴趣的文章:

标签云: