예제 #1
0
  public static int installSilence(Context context, String filePath, boolean isUpdate) {
    File file = new File(filePath);

    if (!file.isFile() || !file.exists()) {
      return 0;
    }
    Uri packageURI = Uri.fromFile(file);
    int installFlags = 0;
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (info != null) {
      try {
        PackageInfo pi =
            pm.getPackageInfo(info.packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        if (pi != null) {
          if (isUpdate) {
            installFlags |= ACA.PackageManager.INSTALL_REPLACE_EXISTING;
          } else {
            return ACA.PackageManager.INSTALL_SUCCEEDED;
          }
        }
      } catch (NameNotFoundException e) {
        // the package did't installed, go ahead
        e.printStackTrace();
      }
      PackageInstallObserver obs = new PackageInstallObserver();
      ACA.PackageManager.installPackage(pm, packageURI, obs, installFlags, info.packageName);
      synchronized (obs) {
        while (!obs.finished) {
          try {
            obs.wait();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
        ;
        return obs.result;
      }
    }
    return 0;
  }
예제 #2
0
  /**
   * uninstall the Third lock app
   *
   * @param packageName the package name of lock
   * @return the result of delete app
   */
  private static int unInstallSilence(String packageName, Context context) {
    if (TextUtils.isEmpty(packageName)) {
      return 0;
    }
    PackageManager pm = context.getPackageManager();

    PackageDeleteObserver pdo = new PackageDeleteObserver();
    ACA.PackageManager.deletePackage(pm, packageName, pdo, 0);
    synchronized (pdo) {
      while (!pdo.finished) {
        try {
          pdo.wait();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      return pdo.result;
      //            if (pdo.result == ACA.PackageManager.DELETE_SUCCEEDED) {
      //                return 1;
      //            }
    }
  }