Please add following permission in the AndroidManifest.xml, before you install it.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Then, at your first time to install APK, you need to RequestPackageInstalls
, then you enable the permission and the res is true, you can install it by the intent. You can refer to the following code.
string _apkPath = "Your downloaed APK path, please download it inyour app folder, when you install it without any read external permission";
#if ANDROID
var packageManager = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.PackageManager;
var res = packageManager.CanRequestPackageInstalls();
if (!res)
{
Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionManageUnknownAppSources, Android.Net.Uri.Parse("package:" + AppInfo.Current.PackageName)));
}else
{
var context = Platform.AppContext;
Java.IO.File apkFile = new Java.IO.File(_apkPath);
var res1=apkFile.Exists();
Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionView);
var uri = Microsoft.Maui.Storage.FileProvider.GetUriForFile(context, context.ApplicationContext.PackageName + ".fileProvider", apkFile);
intent.SetDataAndType(uri, "application/vnd.android.package-archive");
intent.AddFlags(Android.Content.ActivityFlags.NewTask);
intent.AddFlags(Android.Content.ActivityFlags.GrantReadUriPermission);
intent.AddFlags(Android.Content.ActivityFlags.ClearTop);
intent.PutExtra(Android.Content.Intent.ExtraNotUnknownSource, true);
intent.PutExtra("apkPath", _apkPath);
Platform.CurrentActivity.StartActivityForResult(intent, 1);
}
#endif