WEB开发者-分享WEB开发知识,让开发变得更简单!

android快捷卸载第三方应用

1、需要的权限:
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
2、获取所有应用
public List<ResolveInfo> getAllPagckage(Context context)
{
PackageManager pm = context.getPackageManager();

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询,获得所有ResolveInfo对象.
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(
mainIntent, PackageManager.GET_GIDS);
// 调用系统排序,根据name排序
Collections.sort(resolveInfoList,
new ResolveInfo.DisplayNameComparator(pm));
return resolveInfoList;
}
3、过滤出第三方应用
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);
// 第三方应用
if((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)
{
list.add(resolveInfo);
}
}
}
}
4、卸载
(注:1、两种方式均可;2、appPackage为resolveInfo.activityInfo.packageName)
public void uninstallApp(Context context, String appPackage)
{
Uri packageURI = Uri.parse("package:" + appPackage);
//自定义卸载
// Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,
// packageURI);
//((Activity)context).startActivityForResult(uninstallIntent, 0);
//调用系统自带卸载操作进行卸载
Intent uninstallIntent = new Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
context.startActivity(uninstallIntent);
}

暂无相关信息

本文链接:https://www.webkfz.comhttp://www.webkfz.com/bianchengkaifa/Android/34196.html

版权声明:站内所有文章皆来自网络转载,只供分享作用,不代表本站的观点!

发表评论 共有 0 条评论)

联系客服
网站客服 业务合作 QQ
1244305267
公众号
公众号
公众号
返回顶部