Android: get the names of all applications installed on the mobile phone and the package name of the application.

Source: Internet
Author: User

Android: get the names of all applications installed on the mobile phone and the package name of the application.

This is tested on the android simulator. The total number of applications obtained is: 51. The application I installed on this simulator is used for testing.

The following code is just a method. during testing, this method is used to respond to a button. The Code is as follows:

Public void getallappnames (view) {packagemanager PM = getpackagemanager (); // packagemanager. get_uninstalled_packages == 8192 list <packageinfo> list2 = PM. getinstalledpackages (packagemanager. get_uninstalled_packages); // packagemanager. get_shared_library_files = 1024 // list <packageinfo> list2 = PM. getinstalledpackages (packagemanager. get_shared_library_files); // packagemanager. get_meta_data = 128 // list <packagein Fo> list2 = PM. getinstalledpackages (packagemanager. get_meta_data); // list <packageinfo> list2 = PM. getinstalledpackages (0); // list <packageinfo> list2 = PM. getinstalledpackages (-10); // list <packageinfo> list2 = PM. getinstalledpackages (10000); For (packageinfo: list2) {// obtain the name of the installed app on the mobile phone, that is, the name of the app in andriodmainfest. app_name in XML. String appname = packageinfo. applicationinfo. loadlabel (getpackagemanager (). tostring (); // obtain the package name of the application package, that is, the Package Value in andriodmainfest. xml. String packagename = packageinfo. packagename; log. I (TAG, "Application name:" + appname); log. I (TAG, "application package name:" + packagename); j ++;} log. I (TAG, "Total number of applications:" + J );}

Note: parameters in PM. getinstalledpackages (packagemanager. get_uninstalled_packages) range from-10, 0, to 10000,

The final result is the same (51 ). The role of this parameter has not been clarified yet.


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.