0

im working on a app coded in C#. Also im using Visual Studio XAMARIN and my android phone for that.

I want to install a apk programmatically. I download a apk from web programmatically (solved yesterday with the help here) and now i try to install the apk file. I found this: Android: install .apk programmatically

But this is in Java and i cant use java for my Application. i tried to do it like there in C# but failed.

This is the code i tried to use:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(newFile(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

but i cant use things like uri.fromFile etc. Also (im not sure where it was) i read that someone said its not even possible to do it in C# and now i dont know what to belive.

Ray Yago
  • 115
  • 1
  • 1
  • 12

1 Answers1

0

I used the following:-

        Intent promptInstall = new Intent(Intent.ActionView).SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/download/" + filename)), "application/vnd.android.package-archive");
        promptInstall.AddFlags(ActivityFlags.NewTask);
        Android.App.Application.Context.StartActivity(promptInstall);

However, since updating api to 28 (Android 9.0) this no longer works and I'm looking for a solution myself....

Toby Kolk
  • 56
  • 5