1, Required permissions:
<uses-permission&NBSP; android:name= " Com.android.launcher.permission.READ_SETTINGS "/>
2, get all applications
Public list<resolveinfo> Getallpagckage (Context context)
{
Packagemanager pm = Context.getpackagemanager ();
Intent mainintent = new Intent (intent.action_main, NULL);
Mainintent.addcategory (Intent.category_launcher);
//Through the query, get all Resolveinfo objects.
List<resolveinfo> resolveinfolist = pm.queryintentactivities (
mainintent, packagemanager.get_gids);
Invokes the system sort, sorted by name
Collections.sort (resolveinfolist,
New Resolveinfo.displaynamecomparator (PM));
Return Resolveinfolist;
}
3, filtering out Third-party applications
private void Filterpackage (list<resolveinfo> allpackagelist)
{
if! Allpackagelist.isempty ())
{
List.clear ();
int size = Allpackagelist.size ();
Resolveinfo resolveinfo = null;
for (int i = 0; i < size; i++)
{
Resolveinfo = Allpackagelist.get (i);
//third-party application
if (resolveinfo.act IvityInfo.applicationInfo.flags & Applicationinfo.flag_system) <= 0)
{
List.add (resolveinfo);
}
}
}
4, uninstall
(Note: 1, both are available; 2, Apppackage is resolveInfo.activityInfo.packageName)
public void Uninstallapp (Context ConteXT, String Apppackage)
{
Uri Packageuri = Uri.parse ("package:" + apppackage);
Custom uninstall
//Intent uninstallintent = new Intent (Intent.action_delete,
//Packageuri);
//((activity) context). Startactivityforresult (uninstallintent, 0);
//Call system uninstall with uninstall
Intent uninstallintent = new Intent (
Settings.action_application_details_settings, Packageuri);
Context.startactivity (uninstallintent);
}