获取Android唯一设备号
16lz
2021-01-23
public class SystemPropertiesInvoke {
private static final String TAG = “SystemPropertiesInvoke”;
private static Method getLongMethod = null;
private static Method getBooleanMethod = null;
public static long getLong(final String key, final long def) { try { if (getLongMethod == null) { getLongMethod = Class.forName("android.os.SystemProperties") .getMethod("getLong", String.class, long.class); } return ((Long) getLongMethod.invoke(null, key, def)).longValue(); } catch (Exception e) { Log.e(TAG, "Platform error: " + e.toString()); return def; }}public static boolean getBoolean(final String key, final boolean def) { try { if (getBooleanMethod == null) { getBooleanMethod = Class.forName("android.os.SystemProperties") .getMethod("getBoolean", String.class,boolean.class); }
return (Boolean)getBooleanMethod.invoke(null, key, def);
} catch (Exception e) {
Log.e(TAG, “Platform error: ” + e.toString());
return def;
}
}
public static String getString(final String key, final String def) { try { if (getBooleanMethod == null) { getBooleanMethod = Class.forName("android.os.SystemProperties") .getMethod("getString", String.class,boolean.class); }return (String)getBooleanMethod.invoke(null, key, def); } catch (Exception e) { Log.e(TAG, "Platform error: " + e.toString()); return def; }}
}
调用方式
String serial = SystemPropertiesInvoke.getString(“gsm.serial”, “”);
Log.i(“TAG”, “serial==========” + serial);
请求权限
更多相关文章
- Android 应用获取通知栏权限
- Android的权限机制之—— “沙箱”机制sharedUserId跟签名
- 【Android UI】Android开发之View的几种布局方式及实践
- android的内存管理方式
- Android Manifest.permission权限
- Android图文混排实现方式详解
- Android 系统下模拟触点击的功能与权限