Android Quick uninstall third party apps

Source: Internet
Author: User
Tags int size sorted by name

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

Related Article

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.