View required permissions for Android apps (Uses-permission)

Source: Internet
Author: User

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)

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.