原创不易,你们对阿超的赞就是阿超持续更新的动力!)
(以免丢失,建议收藏~~~)
获取设备id
public static String getDeviceId() { if (context == null) { return ""; } return DeviceIdentifier.getAndroidID(context); }
获取ip地址
public static String getIp() { String networkType = getNetworkType(); if (networkType.equals("WiFi")) { WifiManager wifiManager = null; try { wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int i = wifiInfo.getIpAddress(); return intToIp(i); } catch (Exception e) { e.printStackTrace(); return null; } } else if (networkType.equals("2G") || networkType.equals("3G") || networkType.equals("4G")) { 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()) { return inetAddress.getHostAddress().toString(); } } } } catch (Exception ex) { return null; } } else { return null; } return null; } /** * 将ip的整数形式转换成ip形式 */ public static String intToIp(int i) { return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + (i >> 24 & 0xFF); }
获取APP应用程序名称
/** /** * 获取APP应用程序名称 */ public static String getAppName(Context context) { try { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo( context.getPackageName(), 0); int labelRes = packageInfo.applicationInfo.labelRes; return context.getResources().getString(labelRes); } catch (Exception e) { e.printStackTrace(); } return null; }
获取设备名称
public static String getDeviceName() { return Build.DEVICE; }
获取设备型号
public static String getDeviceModel() { return Build.MODEL; }
获取设备处理器
public static String getDeviceBoard() { return Build.BOARD; }
获取设备品牌获取
public static String getDeviceManufacturer() { return Build.MANUFACTURER; }
获取设备制造商
public static String getDeviceManufacturer() { return Build.MANUFACTURER; }
获取设备oaid
方案一
// build.gradle需要引入获取oaid库 compileOnly 'com.github.gzu-liyujiang:Android_CN_OAID:4.2.3' • 1 • 2
public static String getOAID() { if (Build.VERSION.SDK_INT < 29) { return DeviceIdentifier.getIMEI(context)); } else { return DeviceIdentifier.getOAID(context)); } }
方案二
public static String getOAID() { if (context == null) { return ""; } if (DeviceID.supportedOAID(context)) { return DeviceID.getOAID(); } return ""; }
Android获取设备各项信息(设备id、ip地址、设备名称、运行商、品牌、型号、分辨率、处理器、国家码、系统语言、网络类型、oaid、android版本、操作系统版本、mac地址、应用程序签名..)2:https://developer.aliyun.com/article/1473469