public class SystemPropertiesUtils { private static LogUtil log = LogUtil.get(SystemPropertiesUtils.class.getSimpleName()); /** * 设置属性值 * * @param key 长度不能超过31,key.length <= 30 * @param value 长度不能超过91,value.length<=90 */ public static void setProperties(String key, String value) { // android.os.SystemProperties // public static void set(String key, String val) try { log.e("setProperties key=" + key + ",value=" + value); Class<?> cls = Class.forName("android.os.SystemProperties"); Method method = cls.getMethod("set", String.class, String.class); method.invoke(null, key, value); } catch (Exception e) { log.e("setProperties e=" + e.getMessage()); } } /** * 获取属性值 * * @param key 长度不能超过31,key.length <= 30 * @param defValue 默认值 * @return 结果 */ public static String getProperties(String key, String defValue) { // android.os.SystemProperties // public static String get(String key, String def) try { log.e("getProperties key=" + key + ",defValue=" + defValue); Class<?> cls = Class.forName("android.os.SystemProperties"); Method method = cls.getMethod("get", String.class, String.class); return (String) method.invoke(null, key, defValue); } catch (Exception e) { log.e("setProperties e=" + e.getMessage()); } return defValue; } }
Android系统属性工具类
于 2024-06-18 14:14:39 首次发布