Systemproperties类在android.os下,但这个类是隐藏的,上层程序开发无法直接使用,只能通过java反射来调用

SystemPropertiesInvoke.java

package com.as;

import java.lang.reflect.Method;

import android.util.Log;

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);
} //Log.i(TAG,"getBoolean:"+"key:"+key+" def:"+def);
//Log.i(TAG,"getBoolean:"+getBooleanMethod.invoke(null, key, def)); return (Boolean)getBooleanMethod.invoke(null, key, def);
} catch (Exception e) {
Log.e(TAG, "Platform error: " + e.toString());
return def;
}
}
}

最新文章

  1. 缓存工具类CacheHelper
  2. 关于EF的一个简单Demo
  3. Decorate Pattern 装饰者模式
  4. Saas
  5. Python之路【第三篇补充】:Python基础(三)
  6. zepto源码--核心方法6(显示隐藏)--学习笔记
  7. sql server 2008 提示评估期已过的解决方法(升级无效)
  8. Python SSH登陆--pexpect,pxssh
  9. C#之 HashSet(临时笔记,未参考资料,请慎重)
  10. jquery.validate使用攻略
  11. MapReduce优化
  12. C++ BitArray 引用计数实现
  13. C#进程管理程序实现
  14. angular 实现modal windows效果(即模态窗口,半透明的遮罩层),以及bootstrap(css,components,js)的初步学习
  15. WebApi接口请求失败,找不到资源。
  16. 错误处理1: D:\a1-C++\C++作业\第五次1.cpp undefined reference to `vtable for Shape'
  17. C#使用Xamarin开发可移植移动应用(1.入门与Xamarin.Forms页面),附源码
  18. 《javascript设计模式与开发实践》阅读笔记(16)—— 状态模式
  19. 把nginx当完全tcp端口转发器
  20. Character流与Byte流的区别(转)

热门文章

  1. SC || 记不住的正则
  2. Bootstrap历练实例:popover插件中的方法
  3. vue项目各页面间的传值
  4. madplay移植
  5. WebUploader压缩图片上传
  6. 笔记1 python入门学习笔记
  7. python flask学习第1天
  8. Computer HDU - 2196
  9. 二分答案:Poweroj2461-入门基础之二分答案(二分法的应用)
  10. 字符编码,ASCII、Unicode与UTF-8的理解