View the permissions required by the Android app (uses-permission)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.