1. 程式人生 > >Android-刪除指定包名的App

Android-刪除指定包名的App

uninstall bsp 指定 刪除 check delet contex this ext

/**
     * 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

Android-刪除指定包名的App