您的位置:首页 > 移动开发 > Android开发

Android获取进程的权限信息

2016-06-25 17:50 555 查看
手机设置里面就有获取权限信息,所以AppSecurityPermissions类是存在的,只是系统隐藏起来了,咱用反射的技术,从运行时里面把AppSecurityPermissions类获取出来

// 获取权限代码
try {
Class clazz = getClass().getClassLoader().loadClass(
"android.widget.AppSecurityPermissions");// 得到这AppSecurityPermissions对应的字节码
Constructor constructor = clazz.getConstructor(new Class[] {
Context.class, String.class });// 找到这字节码的构造方法,这个AppSecurityPermissions里面的构造方法有两个参数,一个是上下文,一个是string类型的包名
Object object = constructor.newInstance(new Object[] { this,
packname });//newInstance就是得到实例
Method method = clazz.getDeclaredMethod("getPermissionsView",
new Class[] {});//获取里面某一个方法,第一个参数是方法名,第二个是方法所接收的参数,当前这个方法不需要接收参数
View view = (View) method.invoke(object, new Object[] {});//invoke是把这个方法调用起来,第一个参数是激活哪一个对象里的方法,第二个参数是这个方法所接收的参数,当前这个方法不需要接收参数
sv_app_detail.addView(view);

} catch (Exception e) {
e.printStackTrace();
}


另外sv_app_detail 是ScrollView

sv_app_detail = (ScrollView) findViewById(R.id.sv_app_detail);

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: