private Method getLongMethod = null;private Method getStringMethod = null;private Method getIntMethod = null;private Method getBooleanMethod = null;public 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) {        return def;    }}public String getStringMethod(final String key, final String def) {    try {        if (getStringMethod == null) {            getStringMethod = Class.forName("android.os.SystemProperties").getMethod("get", String.class, String.class);        }        return ((String) getStringMethod.invoke(null, key, def)).toString();    } catch (Exception e) {        return def;    }}public int getIntMethod(final String key, final int def) {    try {        if (getIntMethod == null) {            getIntMethod = Class.forName("android.os.SystemProperties")                    .getMethod("getInt", String.class, int.class);        }        return ((Integer) getIntMethod.invoke(null, key, def)).intValue();    } catch (Exception e) {        return def;    }}public boolean getBooleanMethod(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)).booleanValue();    } catch (Exception e) {        return def;    }}

//通过反射设置系统属性

public static void setProperty(String key, String value) {    try {        Class<?> c = Class.forName("android.os.SystemProperties");        Method set = c.getMethod("set", String.class, String.class);        set.invoke(c, key, value );    } catch (Exception e) {        e.printStackTrace();    }}

更多相关文章

  1. android:numeric="integer"属性
  2. Android ---android:autoLink属性
  3. Android控件布局属性大全
  4. android -> 修改自动转为大写 的textAllCaps 属性
  5. Android属性(property)机制
  6. android官方技术文档翻译——工具属性
  7. Activity 属性设置大全

随机推荐

  1. Android Audio代码分析22 - AudioEffect:
  2. android 入门学习笔记 BIG5 与 UTF-8互转
  3. Android屏幕中隐藏标题栏和状态栏
  4. Android(安卓)各国语言Values命名规则
  5. ubuntu 上android 源码编译 全过程(二)
  6. Android uses-permission 权限大全
  7. Android常用Intent
  8. Android短信验证服务分享
  9. Android中ArrayList动态数组用法
  10. Android传感器(五):线性加速度传感器