title: Android PackageInstaller not installing APK
body: <p>Hello StackOverflow users,</p>
  
  <p>i have an Android app outside of the Play Store. It updates itself by downloading a new APK and invoking the installer dialog using an Intent. The update functionality does not work anymore on Android 10.</p>
  
  <p>I need to use the PackageInstaller API on Android 10 now, but i can't get it to work. My app is not a device or profile owner, but since i don't want a silent install so i think it should be fine.</p>
  
  <p>My problem is that as soon as i commit the session absolutely nothing happens.</p>
  
  <pre><code>PackageInstaller installer = activity.PackageManager.PackageInstaller;
  PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstallMode.FullInstall);
  int sessionId = installer.CreateSession(sessionParams);
  PackageInstaller.Session session = installer.OpenSession(sessionId);
  
  var input = new FileStream(pfad, FileMode.Open, FileAccess.Read);
  var packageInSession = session.OpenWrite("package", 0, -1);
  input.CopyTo(packageInSession);
  packageInSession.Close();
  input.Close();
  
  //That this is necessary could be a Xamarin bug.
  GC.Collect();
  GC.WaitForPendingFinalizers();
  GC.Collect();
  
  Intent intent = new Intent(activity, activity.Class);
  intent.SetAction("com.example.android.apis.content.SESSION_API_PACKAGE_INSTALLED");
  PendingIntent pendingIntent = PendingIntent.GetActivity(activity, 0, intent, 0);
  IntentSender statusReceiver = pendingIntent.IntentSender;
  
  // Commit the session (this will start the installation workflow).
  session.Commit(statusReceiver);
  </code></pre>
  
  <p>I took a look at the DDMS and got nothing relevant out of it. One thing that might be of interest is that when i <code>Dispose()</code> the streams, i get an <code>IOException: write failed (EBADF) bad file descriptor</code> which would indicate a bad APK. But i doubt it's that because i can install the APK using a file manager without a hitch. Googling the error didn't lead me anywhere.</p>
  
  <p>How can i fix this problem?</p>