I am attempting to install an apk file using .NET MAUI on an Android device like so:
var bytes = DownloadApkFile();
var file = Path.Combine(FileSystem.Current.CacheDirectory, "app.apk");
File.WriteAllBytes(file, bytes);
var context = Android.App.Application.Context;
Java.IO.File file = new Java.IO.File(path);
using (Android.Content.Intent install = new Android.Content.Intent(Android.Content.Intent.ActionView))
{
var uri = Microsoft.Maui.Storage.FileProvider.GetUriForFile(context, context.ApplicationContext.PackageName + ".fileProvider", file);
install.SetDataAndType(uri, "application/vnd.android.package-archive");
install.AddFlags(Android.Content.ActivityFlags.NewTask);
install.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission);
install.AddFlags(Android.Content.ActivityFlags.ClearTop);
install.PutExtra(Android.Content.Intent.ExtraNotUnknownSource, true);
Platform.CurrentActivity.StartActivity(install);
}
This works perfectly in debug mode, but in release mode I get the following exception: Java.Lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.mycompany.mobile.fileProvider
I thought maybe I needed to add a [ContentProvider]
attribute to the application, but then it no longer builds because of duplicate content providers for androidx.core.content.FileProvider
, so I assume MAUI is including this content provider automatically?