获取Android唯一设备号

来源:互联网 发布:床单淘宝店知乎 编辑:程序博客网 时间:2024/05/23 02:04

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);
请求权限




0 0