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