手机设置里面就有获取权限信息,所以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);
本文介绍如何通过反射技术访问Android系统隐藏的AppSecurityPermissions类,以获取应用的权限信息。在手机设置中虽然可以查看权限,但该类并未直接暴露,通过反射可以在运行时获取到相关信息。
560

被折叠的 条评论
为什么被折叠?



