MainActivity is as follows:
Package cc. testusespermission; import android. app. activity; import android. content. pm. packageInfo; import android. content. pm. packageManager; import android. content. pm. permissionGroupInfo; import android. content. pm. permissionInfo; import android. OS. bundle;/*** Demo Description: * view the permissions required by the Android app (uses-permission) ** reference: * 1 http://blog.csdn.net/bage1988320/article/details/6740292 * 2 http://blog.csdn.net/hjd_love_zzt/article/details/12238301 * Thank you very much ** Note: * The code comment in the Demo is android. permission. INTERNET permission * is used as an example to describe the attributes in detail **/public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); getUsesPermission ("cc. testusespermission ");} private void getUsesPermission (String packageName) {try {PackageManager packageManager = this. getPackageManager (); PackageInfo packageInfo = packageManager. getPackageInfo (packageName, PackageManager. GET_PERMISSIONS); String [] usesPermissionsArray = packageInfo. requestedPermissions; for (int I = 0; I <usesPermissionsArray. length; I ++) {// obtain the name of each permission, for example, android. permission. INTERNET String usesPermissionName = usesPermissionsArray [I]; System. out. println ("usesPermissionName =" + usesPermissionName); // you can use usesPermissionName to obtain the details of this permission. PermissionInfo permissionInfo = packageManager. getPermissionInfo (usesPermissionName, 0); // permission group to which the permission belongs, for example, network communication PermissionGroupInfo permissionGroupInfo = packageManager. getPermissionGroupInfo (permissionInfo. group, 0); System. out. println ("permissionGroup =" + permissionGroupInfo. loadLabel (packageManager ). toString (); // obtain the tag information for this permission, for example, full network access permission String permissionLabel = permissionInfo. loadLabel (packageManager ). toString (); System. out. println ("permissionLabel =" + permissionLabel); // obtain the detailed description of the permission, for example: this application is allowed to create network sockets and use custom network protocols // browsers and some other applications to send data to the Internet. Therefore, the application can send data to the Internet without the permission. string permissionDescription = permissionInfo. loadDescription (packageManager ). toString (); System. out. println ("permissionDescription =" + permissionDescription); System. out. println ("========================================== ====== ");}} catch (Exception e) {// TODO: handle exception }}}
Main. xml is as follows:
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "view permissions required by Android applications (uses-permission)" android: layout_centerInParent = "true"/> </RelativeLayout>
PS:
This example does not require any permissions.