update:2020.06.15
fix:没有推送也能删除应用 add:没有锁定设备不初始化极光推送
This commit is contained in:
@@ -579,11 +579,11 @@ public class ApkUtils {
|
||||
|
||||
private static String[] excludePackageName = {"com.easyold.uiuios"};
|
||||
|
||||
public static List<ApplicationInfo> queryFilterAppInfo(Context context) {
|
||||
public static List<String> queryFilterAppInfo(Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
|
||||
List<ApplicationInfo> applicationInfos = new ArrayList<>();
|
||||
List<String> applicationInfos = new ArrayList<>();
|
||||
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
||||
@@ -597,17 +597,13 @@ public class ApkUtils {
|
||||
}
|
||||
|
||||
for (ApplicationInfo app : appInfos) {
|
||||
// if((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
// {
|
||||
// applicationInfos.add(app);
|
||||
// }
|
||||
if ((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用,会将电话、短信也排除掉
|
||||
{
|
||||
applicationInfos.add(app.packageName);
|
||||
}
|
||||
// if(app.uid > 10000){//通过uid排除系统应用,在一些手机上效果不好
|
||||
// applicationInfos.add(app);
|
||||
// }
|
||||
if (allowPackages.contains(app.packageName) && !Arrays.asList(excludePackageName).contains(app.packageName)) {
|
||||
// if (allowPackages.contains(app.packageName)) {
|
||||
applicationInfos.add(app);
|
||||
}
|
||||
}
|
||||
return applicationInfos;
|
||||
}
|
||||
@@ -616,6 +612,7 @@ public class ApkUtils {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
// 查询所有已经安装的应用程序
|
||||
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
|
||||
|
||||
List<String> packageList = new ArrayList<>();
|
||||
|
||||
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
|
||||
@@ -646,4 +643,22 @@ public class ApkUtils {
|
||||
}
|
||||
return packageList;
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void uninstallAllApp(Context context) {
|
||||
List<String> appList = ApkUtils.queryFilterAppInfo(context);
|
||||
if (null != appList && appList.size() > 0) {
|
||||
for (String packageName : appList) {
|
||||
Log.e("fht", "uninstallAllApp packageName is:" + packageName);
|
||||
if (packageName.equals("com.jiaoguanyi.store") || packageName.equals(BuildConfig.APPLICATION_ID)) {
|
||||
continue;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ApkUtils.uninstall(context, packageName);
|
||||
} else {
|
||||
ApkUtils.deleteApkInSilence(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user