[Android] obtains information about the installed APK files (packageinfo and resolveinfo) on the mobile phone (Application images, application names, and package names)

Source: Internet
Author: User

As we all know, packagemanager can be used to obtain information about the APK files installed on the mobile phone end. The specific code is as follows:

Packagemanager = This. getpackagemanager (); <br/> List <packageinfo> packageinfolist = packagemanager. getinstalledpackages (0 ); 

Through the above method, you can obtain all the applications installed on your mobile phone, including information about the APK package that is manually installed and the pre-installed application software, to distinguish between the two types of software, you can use the following methods:

A. Obtain packageinfo from packageinfolist, and then obtain applicationinfo through packageinfo. applicationinfo.

B. determine the value of (applicationinfo. Flags & applicationinfo. flag_system). If the value is greater than 0, the obtained application is a pre-installed application, and vice versa.

You can check the code and the description has been written in comments.

Get the application code:

/** <Br/> * query non-system applications on the mobile phone <br/> * @ Param context <br/> * @ return <br/> */<br/> Public static list <packageinfo> getallapps (context) {<br/> List <packageinfo> apps = new arraylist <packageinfo> (); <br/> packagemanager pmanager = context. getpackagemanager (); <br/> // obtain all applications on the mobile phone <br/> List <packageinfo> paklist = pmanager. getinstalledpackages (0); <br/> for (INT I = 0; I <paklist. size (); I ++) {<br/> packageinfo Pak = (packageinfo) paklist. get (I); <br/> // determine whether the application is pre-installed. <br/> If (Pak. applicationinfo. flags & Pak. applicationinfo. flag_system) <= 0) {<br/> // customs applications <br/> apps. add (PAK); <br/>}< br/> return Apps; <br/>} 

 

Obtain the image, application name, and package name:

 

Packagemanager pmanager = messagesendactivity. this. getpackagemanager (); <br/> List <packageinfo> applist = utils. getallapps (messagesendactivity. this); </P> <p> for (INT I = 0; I <applist. size (); I ++) {<br/> packageinfo pinfo = applist. get (I); <br/> your iteminfo items item = new your iteminfo (); <br/> // set icon <br/> your item. seticon (pmanager. getapplicationicon (pinfo. applicationinfo); <br/> // Set Application name <br/> your item. setlabel (pmanager. getapplicationlabel (pinfo. applicationinfo ). tostring (); <br/> // set package name <br/> specify item. setpackagename (pinfo. applicationinfo. packagename); </P> <p>} 

The iteminfo class is customized locally. You can ignore it!

In addition, someone may be looking for a shared Application List. Let's talk about it here.

Obtain the code of the shared application:

/** <Br/> * query all apps that support sharing on the mobile phone <br/> * @ Param context <br/> * @ return <br/> */<br/> Public static list <resolveinfo> getmediaapps (context) {<br/> List <resolveinfo> mapps = new arraylist <resolveinfo> (); <br/> intent = new intent (intent. action_send, null); <br/> intent. addcategory (intent. category_default); <br/> intent. settype ("text/plain"); <br/> packagemanager pmanager = context. getpackagemanager (); <br/> mapps = pmanager. queryintentactivities (intent, packagemanager. component_enabled_state_default); </P> <p> return mapps; <br/>} 

Because of this method, the returned packageinfo object is not. But resolveinfo. Therefore, the methods for obtaining images, application names, and package names are different:

Packagemanager pmanager = messagesendactivity. this. getpackagemanager (); </P> <p>/********************** query all apps that support sharing on the mobile phone *** * ****************/<br/> List <resolveinfo> resolvelist = utils. getmediaapps (messagesendactivity. this); </P> <p> for (INT I = 0; I <resolvelist. size (); I ++) {<br/> resolveinfo resolve = resolvelist. get (I); <br/> your iteminfo items item = new your iteminfo (); <br/> // set icon <br/> your item. seticon (resolve. loadicon (pmanager); <br/> // Set Application name <br/> your item. setlabel (resolve. loadlabel (pmanager ). tostring (); <br/> // set package name <br/> specify item. setpackagename (resolve. activityinfo. packagename); </P> <p>} 

Summary:

How to Use packageinfo to obtain specific information:


Packageinfo. packagename

How to obtain the icon: packagemanager. getapplicationicon (applicationinfo)

How to obtain the application name: packagemanager. getapplicationlabel (applicationinfo)

How to obtain permissions: packagemanager. getpackageinfo (packagename, packagemanager. get_permissions)

. Requestedpermissions


How to obtain the specific information through resolveinfo:


How to obtain the package name: resolve. activityinfo. packagename

How to obtain the icon: resolve. loadicon (packagemanager)

How to obtain the application name: resolve. loadlabel (packagemanager). tostring ()

 

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.