As we all know, through the Packagemanager can obtain the mobile phone installed apk file information, the specific code is as follows
[Java]View Plaincopyprint?
- Packagemanager Packagemanager = This.getpackagemanager ();
- list<packageinfo> packageinfolist = packagemanager.getinstalledpackages (0);
Through the above method, you can get all the applications installed in the phone, including the manual installation of the APK package information, but also includes the system preinstalled application software information, to distinguish between the two types of software can use the following methods:
A. PackageInfo obtained from Packageinfolist, and then acquired ApplicationInfo through Packageinfo.applicationinfo.
B. The value of Judgment (Applicationinfo.flags & Applicationinfo.flag_system), which is greater than 0 o'clock, indicates that the acquired app is an app preinstalled by the system, and vice versa is a manually installed app.
You can look at the code and say it's written in the comments.
Get the app's code:
[Java]View Plaincopyprint?
- /**
- * Inquire about non-system applications in mobile phone
- * @param context
- * @return
- */
- public static list<packageinfo> Getallapps (context context) {
- List<packageinfo> apps = new arraylist<packageinfo> ();
- Packagemanager Pmanager = Context.getpackagemanager ();
- Get all apps in your phone
- list<packageinfo> paklist = pmanager.getinstalledpackages (0);
- for (int i = 0; i < paklist.size (); i++) {
- PackageInfo Pak = (packageinfo) paklist.get (i);
- Determine if a non-system preinstalled application
- if ((Pak.applicationInfo.flags & Pak.applicationInfo.FLAG_SYSTEM) <= 0) {
- Customs applications
- Apps.add (Pak);
- }
- }
- return apps;
- }
Get picture, App name, package name:
[Java]View Plaincopyprint?
- 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);
- Shareiteminfo Shareitem = new Shareiteminfo ();
- Set Icon
- Shareitem.seticon (Pmanager.getapplicationicon (pinfo.applicationinfo));
- Set Application Name
- Shareitem.setlabel (Pmanager.getapplicationlabel (pinfo.applicationinfo). toString ());
- Set Package Name
- Shareitem.setpackagename (Pinfo.applicationInfo.packageName);
- }
Where the Shareiteminfo class is my local custom, you can ignore!
Alternatively, someone might be looking for a list of sharing apps, and here's the next one.
Get the code for the app that supports sharing:
[Java]View Plaincopyprint?
- /**
- * Find all the apps that support sharing in your phone
- * @param context
- * @return
- */
- public static list<resolveinfo> Getshareapps (context 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 ();
- Mapps = Pmanager.queryintentactivities (Intent,packagemanager.component_enabled_state_default);
- return Mapps;
- }
Because of this method, the returned PackageInfo object is not. But ResolveInfo. So the way to get pictures, app names, and package names is different, as follows:
[Java]View Plaincopyprint?
- Packagemanager Pmanager = MessageSendActivity.this.getPackageManager ();
- /********************* Find all the apps that support sharing in your phone *********************/
- list<resolveinfo> resolvelist = Utils.getshareapps (messagesendactivity.this);
- for (int i=0;i<resolvelist.size (); i++) {
- ResolveInfo resolve = Resolvelist.get (i);
- Shareiteminfo Shareitem = new Shareiteminfo ();
- Set Icon
- Shareitem.seticon (Resolve.loadicon (Pmanager));
- Set Application Name
- Shareitem.setlabel (Resolve.loadlabel (Pmanager). toString ());
- Set Package Name
- Shareitem.setpackagename (Resolve.activityInfo.packageName);
- }
Summarize:
Get the specific information method by PackageInfo:
Package name Get method: Packageinfo.packagename
Icon Get Get Method: Packagemanager.getapplicationicon (ApplicationInfo)
Application name Get method: Packagemanager.getapplicationlabel (ApplicationInfo)
Access method using permissions: Packagemanager.getpackageinfo (packagename,packagemanager.get_permissions)
. requestedpermissions
Get the specific information method by ResolveInfo:
Package name Get method: Resolve.activityInfo.packageName
Icon Get Get Method: Resolve.loadicon (Packagemanager)
App Name Get method: Resolve.loadlabel (Packagemanager). ToString ()
"Android" gets the installed APK file information (PackageInfo, ResolveInfo) (app image, app name, package name, etc.) from your phone