效果图:
代码实现:
1、MainActivity
package com.njupt.testpermission;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
private LinearLayout ll_list_permission;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ll_list_permission = (LinearLayout) findViewById(R.id.ll_list_permission);
}
public void get(View v){
try {
//android.widget.AppSecurityPermissions
//AppSecurityPermissions asp = new AppSecurityPermissions(this, packageName);
//asp.getPermissionsView()
Class clazz = Class.forName("android.widget.AppSecurityPermissions");
Constructor[] constructors = clazz.getConstructors();
for(Constructor c:constructors){
Class[] parameterTypes = c.getParameterTypes();
for(Class cls:parameterTypes){
System.out.println(cls.getName());
}
System.out.println("*******************************************************");
}
Constructor c = constructors[1];
//第二个参数为你所想要查询的应用的名字
Object obj = c.newInstance(new Object[]{this,"com.njupt.safe"});
Method method = clazz.getMethod("getPermissionsView", null);
View view = (View) method.invoke(obj, null);
ll_list_permission.addView(view);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
2、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/background_dark"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="get"
android:text="获取权限" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/ll_list_permission"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</ScrollView>
</LinearLayout>
3、这个应用本身不需要任何权限,主要是用来查看其他应用的权限。。