Hello,
Before you use Intent to install apk, you can do this by adding following permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
Then, you need to check your application if could install unknown app by var res=packageManager.CanRequestPackageInstalls();
. If not, you can start Activity to enable this permission by users for your application.
#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)));
}
#endif
In the end, you can execute InstallApp._Run();
if user enable the PackageInstalls permission.
#if ANDROID
var packageManager=Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.PackageManager;
var res=packageManager.CanRequestPackageInstalls();
if(res) {
InstallApp._Run();
}
#endif
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.