/**
     * check and delete the old package app if it exists.
     */
    private void checkOldPackage() {
        String packageName = "xxx.xxx.xxx.xxx";
        if (isAvilible(this, packageName)) {
            Intent uninstall_intent = new Intent();
            uninstall_intent.setAction(Intent.ACTION_DELETE);
            uninstall_intent.setData(Uri.parse("package:" + packageName));
            startActivity(uninstall_intent);
        }
    }

    private boolean isAvilible(Context cxt, String packagename) {
        PackageManager pm = cxt.getPackageManager();
        List<PackageInfo> pinfo = pm.getInstalledPackages(0);
        for (int i = 0; i < pinfo.size(); i++) {
            if (pinfo.get(i).packageName.equalsIgnoreCase(packagename)) {
                return true;
            }
        }
        return false;
    }

1.查找是否存在指定包名的App

2.创建Intent,删除指定包名的App

 

相关文章:

  • 2021-11-28
  • 2021-11-23
  • 2021-04-24
  • 2019-12-05
  • 2021-09-18
  • 2021-11-06
  • 2021-11-20
  • 2021-11-20
猜你喜欢
  • 2021-11-27
  • 2021-09-06
  • 2021-05-06
  • 2021-06-23
  • 2021-06-27
  • 2021-12-12
  • 2021-10-24
  • 2021-04-02
相关资源
相似解决方案