Get information about apps (packages) in Android----Packagemanager

Source: Internet
Author: User

This section is about how to get information about applications in Android, including PackageName, label, icon, occupancy, and so on. Specifically divided into two

section, the plan is as follows:

The first part: Get the application PackageName, label, icon and so on;

Part II: Gets the size of the application, including: Cache Size (cachsize), data Size (datasize).

Each section has a simple and rich set of examples for you to be sure you won't miss.

The Android system provides us with a number of service management classes, including Activitymanager, PowerManager (Power Management), Audiomanager (audio management)

such as In addition to this, a Packagemanger management class is provided, whose primary responsibility is to manage application packages. With it, we can get application information.

Introduction: Anroidmanifest.xml File Node Description:

I. Introduction to related Classes Packageiteminfo class

Description : The base class for all nodes in the Androidmanifest.xml file provides basic information about these nodes: a label, icon, Meta-data. It does not

Directly, but inherits from the subclass and then calls the appropriate method.

characters commonly used segment :

public int icon Gets the value of the resource picture in the R file (corresponding to the Android:icon property)

public int Labelres Gets the value of the label in the R file (corresponding to the Android:label property)

Public String name Gets the name value of the node (corresponding to the Android:name property)

Public String PackageName Gets the package name of the application (corresponding to the Android:packagename property)

Common methods :

drawable LoadIcon (packagemanager pm) get an image of the current application

Charsequence Loadlabel (packagemanager pm) Get the label of the current application

Activityinfo class inherits from Packageiteminfo

Description : Obtain information about the <activity/> or <receiver/> node in the application. We can use it to get any attributes we set, including theme, Launchmode, Launchmode, etc.

Common methods are inherited to LoadIcon () and Loadlabel () in the Packageiteminfo class

ServiceInfo class

Description : Similar to Activityinfo, it also inherits from Packageiteminfo, except that it represents the <service> node information.

ApplicationInfo class inherits from Packageiteminfo

Description : Gets information about the <application> node in a specific reference program.

Field Description :

Flags field: Flag_system System Application

Flag_external_storage indicates that the app is installed in SDcard

Common methods are inherited to LoadIcon () and Loadlabel () in the Packageiteminfo class

Resolveinfo class

Description : Gets information about the previous level of the directory based on the <intent> node, usually <activity>, <receiver>, <service> node information.

characters commonly used segment :

Public Activityinfo Activityinfo Get Activityinfo object, i.e. <activity> or <receiver > node information

Public serviceinfo serviceinfo Get ServiceInfo object, i.e. <service> node information

Common Methods :

drawable LoadIcon (packagemanager pm) get an image of the current application

Charsequence Loadlabel (packagemanager pm) Get the label of the current application

PackageInfo class

Description : Obtain the information for the Androidmanifest.xml file manually.

characters commonly used segment :

Public String PackageName Package name

Public activityinfo[] Activities all <activity> node information

Public ApplicationInfo applicationinfo <application> node information, only one

Public activityinfo[] Receivers all <receiver> node information, multiple

Public serviceinfo[] services all <service> node information, multiple

Packagemanger class

Description : Gets the installed application information. Can be obtained through the Getpackagemanager () method.

Common Methods :

Public Abstract Packagemanager getpackagemanager ()

function: Get a Packagemanger object

Public Abstrac Tdrawable Getapplicationicon (Stringpackagename)

Parameters: PackageName Package Name

Function: Returns the icon for the given package name, otherwise returns null

Public Abstract applicationinfo getapplicationinfo (String packagename, int flags)

Parameters: PackageName Package Name

Flags The APPLICATIONINFO is this flags tag, which can usually be given directly to the constant 0 .

Function: Returns the ApplicationInfo object

Public Abstract List<applicationinfo> getinstalledapplications (int flags)

Parameters: Flag is generally get_uninstalled_packages, then all ApplicationInfo are returned.

we can do this to ApplicationInfo . The flags filter to get what we need.

Function: Returns all packageinfo for a given condition

Public Abstract List<packageinfo> getinstalledpackages (int flags)

Parameters above

Function: Returns all packageinfo for a given condition

Public AbstractResolveInfo resolveactivity (Intent Intent, int flags)

Parameters: Intent search condition, action and category configured by activity

Flags:MATCH_DEFAULT_ONLY:Category must have category_default activity in order to match

Get_intent_filters: Matching INTENT conditions can be

Get_resolved_filter: Matching intent conditions can be

Function: Returns the Resolveinfo object for a given condition (essentially activity)

Public abstract List<ResolveInfo> Queryintentactivities (Intent inte NT, int flags)

Parameters above

Function: Returns all Resolveinfo objects of a given condition (essentially activity), collection object

Public Abstract ResolveInfo resolveservice (Intent Intent, int flags)

Parameters above

Function: Returns the Resolveinfo object for a given condition (essentially a service)

Public abstract List<ResolveInfo> Queryintentservices (Intent int ENT, int flags)

Parameters above

Function: Returns all Resolveinfo objects of a given condition (essentially service), collection object

Second, demo explanation

From the previous introduction, I believe you must know very well, essentially, these xxxinfo classes are just the information we define in the Androidmanifest.xml file,

Knowing that, it's not very difficult to understand.

Below I use two simple answers to the demo, to apply.

Demo 1: Use the Queryintentactivities () method to query all Android systems with Action_main and Category_launcher

Intent application, after clicking, can launch the application, and plainly is to do a similar home program simple launcher.

Demo 2: Get the app through the Getinstalledapplications () method, then filter it, find out what we need for third-party applications, system applications, installation in SDcard applications.

Get information about apps (packages) in Android----Packagemanager

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.