title: Problem with update android app silently without user interaction and root permission
body: <p>I know there is many stack-overflow posts for this question, but i couldn't solve my problem using any of them.<br>
  My app is only available for a limited group of people(inner company app), so i can't publish it in an app store and i want it to be updated automatically when i release a new version on the app server.<br>
  it is a <code>device admin</code> app with no root permission. i found <a href="https://www.sisik.eu/blog/android/dev-admin/update-app" rel="nofollow noreferrer">this</a> approach to achieve this goal but it didn't work.<br></p>
  
  <p>I have this permission in my <code>AndroidManifest.xml</code> file to install packages:</p>
  
  <pre><code>   &lt;uses-permission android:name="android.permission.INSTALL_PACKAGES" /&gt;
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  private void installPackage(Context context, String filePath, String packageName)
          throws IOException
  {
      Log.d(TAG, "installPackage: start");
      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);
      //
      InputStream in = new FileInputStream(new File(filePath));
      OutputStream out = session.openWrite(packageName, 0, -1);
      IOUtils.copyStream(in, out);
      //
      session.fsync(out);
      in.close();
      out.close();
      //
      session.commit(PendingIntent.getActivity(context, 112233, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT).getIntentSender());
      Log.d(TAG, "installPackage: commit");
  }
  </code></pre>
  
  <p>And this is <code>onCreate</code> method of my <code>MainActivity</code> class:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      ComponentName componentName = new ComponentName(this, AdminReceiver.class);
      DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
      if (getIntent() != null &amp;&amp; dpm != null)
      {
          Log.d(TAG, "onCreate: is app admin : " + dpm.isAdminActive(componentName));
          Log.d(TAG, "onCreate: status : " + getIntent().getIntExtra("android.content.pm.extra.STATUS", 1000));
          Log.d(TAG, "onCreate: intent : " + getIntent().getParcelableExtra("android.intent.extra.INTENT"));
      }
  }
  </code></pre>
  
  <p>and this is my <code>logcat</code> result :</p>
  
  <pre><code>2019-07-08 15:03:24.147 5841-5841/com.test.learncheshmak D/AutoUpdateHelper: downloadUpdate: SUCCESSFUL
  2019-07-08 15:03:24.147 5841-5841/com.test.learncheshmak D/AutoUpdateHelper: installPackage: start
  2019-07-08 15:03:24.295 5841-5841/com.test.learncheshmak D/AutoUpdateHelper: installPackage: commit
  2019-07-08 15:03:24.298 5841-5895/com.test.learncheshmak V/FA: Recording user engagement, ms: 11740
  2019-07-08 15:03:24.302 5841-5841/com.test.learncheshmak W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@fe51cb8
  2019-07-08 15:03:24.307 5841-5841/com.test.learncheshmak V/FA: onActivityCreated
  2019-07-08 15:03:24.308 5841-5895/com.test.learncheshmak V/FA: Connecting to remote service
  2019-07-08 15:03:24.308 5841-5841/com.test.learncheshmak D/MainActivity: onCreate: is app admin : true
  2019-07-08 15:03:24.309 5841-5841/com.test.learncheshmak D/MainActivity: onCreate: status : -1
  2019-07-08 15:03:24.309 5841-5841/com.test.learncheshmak D/MainActivity: onCreate: intent : Intent { act=android.content.pm.action.CONFIRM_PERMISSIONS pkg=com.google.android.packageinstaller (has extras) }
  </code></pre>
  
  <p>Here, as we see, status is -1. according to <a href="https://developer.android.com/reference/android/content/pm/PackageInstaller.html#STATUS_PENDING_USER_ACTION" rel="nofollow noreferrer">this</a> document i got <code>STATUS_PENDING_USER_ACTION</code> and it determine we need user prompt to update our app.but this app is a device admin(device owner) app and according to <a href="https://developer.android.com/reference/android/content/pm/PackageInstaller.html" rel="nofollow noreferrer">this</a> document: </p>
  
  <blockquote>
    <p>Committing may require user intervention to complete the installation, unless the caller falls into one of the following categories, in which case the installation will complete automatically.</p>
    
    <ul>
    <li>the device owner</li>
    <li>the affiliated profile owner</li>
    </ul>
  </blockquote>
  
  <p>so if app be <code>device owner</code> install progress will perform automatically (with out user prompt). then why do i get <code>STATUS_PENDING_USER_ACTION</code> while my app is a <code>device admin</code> app?</p>