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.