android通过反射来获取系统属性SystemProperties
来源:互联网 发布:sql server2012向导 编辑:程序博客网 时间:2024/05/16 16:22
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(); }}
阅读全文
0 0
- android通过反射来获取系统属性SystemProperties
- Android : 反射机制获取或设置系统属性(SystemProperties)
- Android : 反射机制获取或设置系统属性(SystemProperties)
- Android : 反射机制获取或设置系统属性(SystemProperties)
- Android 反射机制获取或设置系统属性(SystemProperties)
- Android 属性系统(SystemProperties)
- Android添加自己的系统属性(反射调用SystemProperties)
- Android Systemproperties Android系统属性
- Android系统属性SystemProperties分析
- Android 系统属性 SystemProperties 分析
- Android系统属性SystemProperties分析
- Android SystemProperties 系统属性分析
- android设置系统属性SystemProperties
- Android系统属性SystemProperties分析 .
- Android系统属性SystemProperties…
- Android SystemProperties系统属性分析
- Android系统属性SystemProperties分析
- Android系统属性SystemProperties分析
- 关于OpenGL中深度截取(GL_DEPTH_CLAMP)的讲解
- deeplearning-Regularization
- Java基础------构造器
- poj1679 The Unique MST
- Spark之分区
- android通过反射来获取系统属性SystemProperties
- Android_EventBus
- 致——世界上最幸福的女孩——Chtholly
- HDU
- poj1789 Truck History
- GenericServlet抽象类以及过滤器
- 1213: [视频]【计算几何】面积
- maven 下载、安装、配置详解
- Spark之join