title: Can a device admin in android install a package?
body: <p>Is it possible to <strong>install an APK</strong> once the application has become <strong>device admin</strong>.
  I tried installing package using the code below but it didn't work.</p>
  
  <pre><code>private static final String ACTION_INSTALL_COMPLETE = "com.test.sampleapp_dev.INSTALL_COMPLETE";
  
  public static boolean installPackage(Context context, InputStream in, String packageName)
          throws IOException {
      PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
      PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
              PackageInstaller.SessionParams.MODE_FULL_INSTALL);
      params.setAppPackageName(packageName);
      // set params
      int sessionId = packageInstaller.createSession(params);
      PackageInstaller.Session session = packageInstaller.openSession(sessionId);
      OutputStream out = session.openWrite("COSU", 0, -1);
      byte[] buffer = new byte[65536];
      int c;
      while ((c = in.read(buffer)) != -1) {
          out.write(buffer, 0, c);
      }
      session.fsync(out);
      in.close();
      out.close();
  
      session.commit(createIntentSender(context, sessionId));
      return true;
  }
  
  private static IntentSender createIntentSender(Context context, int sessionId) {
      PendingIntent pendingIntent = PendingIntent.getBroadcast(
              context,
              sessionId,
              new Intent(ACTION_INSTALL_COMPLETE),
              0);
      return pendingIntent.getIntentSender();
  }
  </code></pre>