title: How to install app using PackageInstaller for Profile Owner?
body: <p>I am trying to install a apk file using Package Installer. My app is current profile owner. The method is completing successfully but in my BroadcastReceiver I am getting PackageInstaller.STATUS_PENDING_USER_ACTION. As per android docs <a href="https://developer.android.com/reference/android/content/pm/PackageInstaller" rel="nofollow noreferrer">https://developer.android.com/reference/android/content/pm/PackageInstaller</a> app should be able to silently install apk if it is a profile owner.</p>
  
  <pre><code>     public static boolean installPackage(Context context, InputStream 
     in, 
         String packageName)
          throws IOException {
        final PackageInstaller packageInstaller = 
      context.getPackageManager().getPackageInstaller();
      final PackageInstaller.SessionParams params = new 
       PackageInstaller.SessionParams(
              PackageInstaller.SessionParams.MODE_FULL_INSTALL);
      params.setAppPackageName(packageName);
      // set params
      final int sessionId = packageInstaller.createSession(params);
      final PackageInstaller.Session session = 
     packageInstaller.openSession(sessionId);
      final OutputStream out = session.openWrite("TestDPC", 0, -1);
      final 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(createInstallIntentSender(context, sessionId));
         return true;
      }
  </code></pre>