欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 删除指定包名的App实例代码

程序员文章站 2022-10-10 12:46:24
废话不多说了,直接给大家贴代码了,具体代码如下所示; /** * check and delete the old package app if it e...

废话不多说了,直接给大家贴代码了,具体代码如下所示;

/**
   * 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实例代码,希望对大家有所帮助