Android app Information Retrieval

Source: Internet
Author: User

 

Packagemanager = This. getpackagemanager ();
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:

Public static list <packageinfo> getallapps (context ){
  List <packageinfo> apps = new arraylist <packageinfo> ();
  Packagemanager pmanager = context. getpackagemanager ();
  // Obtain all applications on the mobile phone
  List <packageinfo> paklist = pmanager. getinstalledpackages (0 );
  For (INT I = 0; I <paklist. Size (); I ++ ){
 Packageinfo Pak = (packageinfo) paklist. Get (I );
 // Determine whether the application is pre-installed.
 If (Pak. applicationinfo. Flags & Pak. applicationinfo. flag_system) <= 0 ){
 // Customs applications
 Apps. Add (PAK );
 }
  }
  Return Apps;
}

Obtain the image, application name, and package name:

       Packagemanager pmanager = messagesendactivity. This. getpackagemanager ();
       List <packageinfo> applist = Utils. getallapps (messagesendactivity. This );
        
       For (INT I = 0; I <applist. Size (); I ++ ){
       Packageinfo pinfo = applist. Get (I );
       Required iteminfo items item = new required iteminfo ();
       // Set icon
       Using item. seticon (pmanager. getapplicationicon (pinfo. applicationinfo ));
       // Set Application name
       Using item. setlabel (pmanager. getapplicationlabel (pinfo. applicationinfo). tostring ());
       // Set package name
       Using item. setpackagename (pinfo. applicationinfo. packagename );
       
       }

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:

  
Public static list <resolveinfo> getmediaapps (context ){
   List <resolveinfo> mapps = new arraylist <resolveinfo> ();
   Intent intent = new intent (intent. action_send, null );
   Intent. addcategory (intent. category_default );
   Intent. settype ("text/plain ");
   Packagemanager pmanager = context. getpackagemanager ();
   

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.