Http://www.tuicool.com/articles/zq2meq
Mainactivity 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 required permissions for Android apps (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 * * Remark Description: * Code comment in demo is Android.permi Ssion. Internet permissions * For an example, the properties are described in detail * */PublicClassMainactivityExtendsActivity { @Override Protectedvoid OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Getusespermission ("Cc.testusespermission");} Privatevoid 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++) { Get the name of each permission, such as: Android.permission.INTERNET String Usespermissionname=usespermissionsarray[i]; System.out.println ("Usespermissionname=" +usespermissionname); Get more information about this permission through Usespermissionname Permissioninfo Permissioninfo=packagemanager.getpermissioninfo (Usespermissionname,0); The permission group to which this permission belongs, for example: network traffic Permissiongroupinfo permissiongroupinfo = Packagemanager.getpermissiongroupinfo (PermissionInfo.group,0); System.out.println ("Permissiongroup=" + Permissiongroupinfo.loadlabel (Packagemanager). toString ()); Gets the label information for the permission, such as full network access permissions String Permissionlabel=permissioninfo.loadlabel (Packagemanager). toString (); System.out.println ("Permissionlabel=" +permissionlabel); Gets a detailed description of the permission, such as: Allow the app to create a network socket and use a custom network protocol Browsers and other apps provide a way to send data to the Internet, so apps can send data to the Internet without that permission. String permissiondescription=permissioninfo.loaddescription (Packagemanager). toString (); System.out.println ( "permissiondescription=" + Permissiondescription); System.out.println ( "==========================================="); } } catch (Exception e) { //Todo:handle exception } }}
Main.xml 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 required permissions for Android apps (uses-permission)" android:layout_centerinparent= "true"/></RELATIVELAYOUT>
Ps:
The example itself is not required for any permissions
View required permissions for Android apps (Uses-permission)