title: Android 10 - Using PackageManager to install new version of apk instead of Intents doesn't really work
body: <p>The way my apk updates currently is through the new apk installing itself over the old one(while not overwriting the local database or settings).</p>
  
  <p>So since Android 10(API 29) <code>ACTION_VIEW</code> was deprecated so this doesn't really work anymore:</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW);
  //output file is the apk downloaded earlier
  intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
  startActivity(intent);
  </code></pre>
  
  <p>Following different answers I've found over the internet I need to start using PackageInstaller instead. Looking at the demo found in the Android docs I get to this:</p>
  
  <pre><code>Intent intent = new Intent(PSMentorActivity.this,InstallApkSessionApi.class);
  intent.putExtra("apkFile",outputFile);
  this.startActivity(intent);
  </code></pre>
  
  <p>Where InstallApkSessionApi contains a button that when pressed should start the install window:</p>
  
  <pre><code>PackageInstaller packageInstaller = getPackageManager().getPackageInstaller();
  PackageInstaller.SessionParams params = new 
      PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL);
  int sessionId = packageInstaller.createSession(params);
  session = packageInstaller.openSession(sessionId);
  addApkToInstallSession(file, session);
  // Create an install status receiver.
  Context context = InstallApkSessionApi.this;
  Intent intent = new Intent(context, InstallApkSessionApi.class);
  intent.setAction(PACKAGE_INSTALLED_ACTION);
  PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
  IntentSender statusReceiver = pendingIntent.getIntentSender();
  // Commit the session (this will start the installation workflow).
  session.commit(statusReceiver);
  </code></pre>
  
  <p>Simple enough, albeit more complicated compared to the past. The response I get in onNewIntent is always:</p>
  
  <pre><code> case PackageInstaller.STATUS_FAILURE:
                Toast.makeText(this, "Install failed!10 " + status + ", " + message,
                              Toast.LENGTH_SHORT).show();
                break;
  </code></pre>
  
  <p>where the status and message take the following values: <code>status=1, message= "INSTALL_FAILED_INTERNAL_ERROR: Permission denied"</code>.</p>
  
  <p>So I assumed it was a problem with permissions. I already had permissions in place over reading and writing to storage. Other related permissions are: <code>INSTALL_PACKAGES</code> and <code>REQUEST_INSTALL_PACKAGES</code> which I cannot use due to the first not being intended for third party uses and the latter being signature level.</p>
  
  <p>Is there something I am terribly missing or is there not a way for me to update my Apk without going through google play? </p>