Obtain the System Application List using Android

Source: Internet
Author: User

This article describes how to obtain the list of system applications in Android.

 

The Android system provides many service management classes, including ActivityManager, PowerManager (power management), and AudioManager (audio management. In addition, a PackageManger management class is provided to manage application packages. With this, we can get the application information.

 

Functions of PackageManager:

• Install and uninstall applications

• Query permission information

• Query Application-related information (application, activity, Cycler, service, provider, and related attributes)

• Query installed applications

• Add and delete permission

• Clear user data, cache, and code segments

We can use PackageManager to display the list of installed applications or system programs.

 

Introduction to related classes

PackageItemInfo class

Note: base classes of all nodes in the AndroidManifest. xml file provide basic information about these nodes: a label, icon, and meta-data. Instead of directly using it, it inherits from the subclass and then calls the corresponding method.

 

Common fields:

Public int icon obtains the value of the resource image in the R file (corresponding to the android: icon attribute)

Public int labelRes get the value of the label in the R file (corresponding to the android: label attribute)

Public String name: Get the name value of the node (corresponding to the android: name attribute)

Public String packagename get the package name of the application (corresponding to the android: packagename attribute)

 

Common Methods:

Drawable loadIcon (PackageManager pm) to get the image of the current application

CharSequence loadLabel (PackageManager pm) obtains the label of the current application

 

ActivityInfo class

Inherited from PackageItemInfo

Description: obtains information about <activity/> or <worker ER/> nodes in an application.

We can use it to obtain any attributes we set, including theme, launchMode, and launchmode.

The common methods inherit from loadIcon () and loadLabel () in the PackageItemInfo class ()

 

ServiceInfo class

Note: similar to ActivityInfo, it also inherits from PackageItemInfo, but it represents <service> node information.

 

ApplicationInfo class

Inherited from PackageItemInfo

Description: obtains information about <application> nodes in a specified reference program.

Field description:

Flags field: FLAG_SYSTEM System Application

FLAG_EXTERNAL_STORAGE indicates that the application is installed in sdcard.

 

The common methods inherit from loadIcon () and loadLabel () in the PackageItemInfo class ()

 

ResolveInfo class

Note: You can obtain information about the last-level directories Based on the <intent> node, which is usually the <activity>, <worker ER>, and <service> node information.

Common fields:

Public ActivityInfo activityInfo gets the ActivityInfo object, that is, the <activity> or <worker ER> node information.

Public ServiceInfo serviceInfo obtains the ServiceInfo object, that is, the <activity> node information.

 

Common Methods:

Drawable loadIcon (PackageManager pm) to get the image of the current application

CharSequence loadLabel (PackageManager pm) obtains the label of the current application

 

PackageInfo class

Note: You can manually obtain information about the AndroidManifest. xml file.

Common fields:

Public String packageName package name

Public ActivityInfo [] activities all <activity> node Information

Public ApplicationInfo applicationInfo <application> node information, only one

Public ActivityInfo [] receivers all <worker ER> node information, multiple

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

 

PackageManger class

Description: obtains information about installed applications.

You can use the getPackageManager () method.

 

Common Methods:

Public abstract PackageManager getPackageManager ()

Function: obtain a PackageManger object.

 

Public abstrac tDrawable getApplicationIcon (StringpackageName)

Parameter: packageName package name

Function: returns the icon of the specified package name. Otherwise, null is returned.

 

Public abstract ApplicationInfo getApplicationInfo (String packageName, int flags)

Parameter: packagename package name flags the ApplicationInfo is the flags mark, which can be directly assigned to the constant 0.

Function: returns the ApplicationInfo object.

 

Public abstract List <ApplicationInfo> getInstalledApplications (int flags)

Parameter: flag is generally GET_UNINSTALLED_PACKAGES, then all ApplicationInfo will be returned.

We can filter flags of ApplicationInfo to obtain what we need.

Function: returns all PackageInfo for a given condition.

 

Public abstract List <PackageInfo> getInstalledPackages (int flags)

The parameters are as follows:

Function: returns all PackageInfo for a given condition.

 

Public incluactresolveinfo resolveActivity (Intent intent, int flags)

Parameter: intent search condition. The action and category flags: MATCH_DEFAULT_ONLY: Category must contain the CATEGORY_DEFAULT Activity to match GET_INTENT_FILTERS: match the Intent condition. GET_RESOLVED_FILTER: matches the Intent condition. function: returns the ResolveInfo object of the given condition (essentially Activity)

 

Public abstract List <ResolveInfo> queryIntentActivities (Intent intent, int flags)

Same as above

Function: returns all the ResolveInfo objects of a given condition (essentially Activity) and collection objects.

 

Public abstract ResolveInfo resolveService (Intent intent, int flags)

Same as above

Function: returns the ResolveInfo object for a given condition (essentially a Service)

 

Public abstract List <ResolveInfo> queryIntentServices (Intent intent, int flags)

Same as above

Function: returns all the ResolveInfo objects of a given condition (essentially a Service) and collection objects.

 

 The running example is shown in:

 

 

Download Sample Code: Click to download

 

Finally, I hope to reprint friends can respect the author's labor results, plus reprint address: http://www.cnblogs.com/hanyonglu/archive/2012/03/18/2404431.html thank you.

 

Complete. Pai_^

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.