Obtains information about all applications, determines system applications or third-party applications, and monitors application installation and uninstallation.

Source: Internet
Author: User

Obtain all applications and related information


Method 1: resolveinfo

Get all applications: packagemanager = getpackagemanager (); intent mintent = new intent (intent. action_main, null); mintent. addcategory (intent. category_launcher); List <resolveinfo> listallapps = packagemanager. queryintentactivities (mintent, 0); determines whether the system is applied: resolveinfo appinfo = listallapps. get (position); string pkgname = appinfo. activityinfo. packagename; // obtain the package name // obtain packageinfo mpackageinfo Based on the package name; (exception must be handled) mpackageinfo = mcontext. getpackagemanager (). getpackageinfo (pkgname, 0); If (mpackageinfo. applicationinfo. flags & applicationinfo. flag_system) <= 0) {// third-party application} else {// System Application} obtain the related information: resolveinfo mresolveinfo; obtain the package name: mresolveinfo. activityinfo. packagename; get icon: mresolveinfo. loadicon (packagemanager); get the application name: mresolveinfo. loadlabel (packagemanager ). tostring ();


Method 2: packageinfo

Obtain all applications: packagemanager = This. getpackagemanager (); List <packageinfo> packageinfolist = packageinfolist. getinstalledpackages (0); determines whether the system is applied: List <packageinfo> apps = new arraylist <packageinfo> (); For (INT I = 0; I <packageinfolist. size (); I ++) {packageinfo Pak = (packageinfo) packageinfolist. get (I); // determine whether the application is pre-installed by the system if (Pak. applicationinfo. flags & Pak. applicationinfo. flag_system) <= 0) {// third-party apps. add (PAK);} else {// System Application} obtain information: packageinfo mpackageinfo; obtain package name: mpackageinfo. packagename get icon: mpackageinfo. getapplicationicon (applicationinfo); obtain the application name: mpackageinfo. getapplicationlabel (applicationinfo); get permission: mpackageinfo. getpackageinfo (packagename, packagemanager. get_permissions ). requestedpermissions;

Install and uninstall the listening application:

/////////// Register the broadcast, listen to the installation and uninstallation of Public void onreceive (context, intent) {If (intent. getaction (). equals ("android. intent. action. package_added ") {// obtain the package name string packagename = intent. getdatastring ();} else if (intent. getaction (). equals ("android. intent. action. package_removed ") {// obtain the package name string packagename = intent. getdatastring ();}}



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.