Before I updated to visual studio 19 and Android 10 (Q), I successfully installed third party apps with my app with the following 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(); packageInSession.Dispose(); input.Dispose(); //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);
When i Dispose() the streams, i get an IOException: write failed (EBADF) bad file descriptor which would indicate a bad APK.
But this is unlikely because the code in visual studio 2017 works with the Android 9 target.
Hope somebody can help me and thank you in advance!