Permission for Android to read an installed package

Source: Internet
Author: User

Recently, you just need to obtain the permission of the installed APK package.

 

As we all know, Android permission declarations are stored in androidmanifest. xml.

The format in the uses-Permission field is as follows:

<Uses-Permission Android: Name = "write_external_storage"/>

 

If you want to obtain the content in this tag

The following code is required:

 

 

Packagemanager PM = This. getpackagemanager (); <br/> packageinfo Info; <br/> try {<br/> info = PM. getpackageinfo (getpackagename (), packagemanager. get_permissions); <br/> string result = NULL; <br/> string [] packagepermissions = info. requestedpermissions; <br/> log. I ("name", info. packagename); <br/> If (packagepermissions! = NULL) {<br/> for (Int J = 0; j <packagepermissions. length; j ++) {<br/> log. I ("result", packagepermissions [J]); <br/>}</P> <p >}else {<br/> log. I ("name", info. packagename + ": No permissions"); <br/>}< br/>} catch (namenotfoundexception E) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>} 

 

 

Note that the flag of the getpackageinfo function must be set to packagemanager. get_permissions.

 

The first parameter is to write string packagename, that is, the package name that you want to obtain permissions.

You can write the name of any installed package to obtain the permission.

 

 

 

This article is owned by Zeng Yang, a csdn blog blogger.

Bytes

Related Article

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.