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