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 ();