Android-删除指定包名的App_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Android-删除指定包名的App

Android-删除指定包名的App

 2017/7/28 5:34:56  清风@_@  程序员俱乐部  我要评论(0)
  • 摘要:/***checkanddeletetheoldpackageappifitexists.*/privatevoidcheckOldPackage(){StringpackageName="xxx.xxx.xxx.xxx";if(isAvilible(this,packageName)){Intentuninstall_intent=newIntent();uninstall_intent.setAction(Intent.ACTION_DELETE);uninstall_intent
  • 标签:android APP
/**
     * 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

 

发表评论
用户名: 匿名