Android quick uninstall third-party applications

Source: Internet
Author: User

1. required permissions:
<Uses-permission android: name = "com. android. launcher. permission. READ_SETTINGS"/>
2. Obtain 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 );
// Obtain all the ResolveInfo objects through the query.
List <ResolveInfo> resolveInfoList = pm. queryIntentActivities (
MainIntent, PackageManager. GET_GIDS );
// Sort the call system by name
Collections. sort (resolveInfoList,
New ResolveInfo. DisplayNameComparator (pm ));
Return resolveInfoList;
}
3. filter 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 applications
If (resolveInfo. activityInfo. applicationInfo. flags & ApplicationInfo. FLAG_SYSTEM) <= 0)
{
List. add (resolveInfo );
}
}
}
}
4. Uninstall
(Note: 1. Both methods are supported; 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 the system's own uninstall operation to uninstall it
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.