question

LukVandevyvere-5800 avatar image
0 Votes"
LukVandevyvere-5800 asked ·

Automatically updating a Xamarin.Forms application

Hi, I don't know if this is the right place to ask this question, but here goes:

I have a Xamarin.Forms application that downloads an apk-file (from my GitHub-repository).

When executing that apk-file, I get a security-error:
Java.Lang.SecurityException: "UID 10105" does not have permission to content:... .apk [user 0]"

Here's my Android-code:

Intent intent = new Intent(Intent.ActionView);
Android.Net.Uri fileUri = null;
if ((int)Build.VERSION.SdkInt < 23)
fileUri = Android.Net.Uri.FromFile(new Java.IO.File(path));
else
fileUri = FileProvider.GetUriForFile(AutoUpdate.Context, AutoUpdate.Authority, new Java.IO.File(path));

intent.SetDataAndType(fileUri, "application/vnd.android.package-archive");
intent.SetFlags(ActivityFlags.GrantReadUriPermission);

AutoUpdate.Context.StartActivity(intent);

In the manifest-page of the Android-project, the following permissions have been checked:
- INSTALL_PACKAGES
- READ_EXTERNAL_STORAGE
- REQUEST_INSTALL_PACKAGES
- RESTART_PACKAGES


What am I doing wrong ?


Luk.

dotnet-xamarinformsdotnet-android
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered ·

Hello,


Welcome to our Microsoft Q&A platform!

We couldn't see the details of your code, but you can recheck if you have added the following code to your AndroidManifest.xml inside the tags, ,for example:

         <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.yourcompany.XamarinFormsCamera.fileprovider" android:exported="false" android:grantUriPermissions="true">
         <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
     </provider>

And add file file_paths.xml into folder xml in android resource folder, for example:

 <?xml version="1.0" encoding="UTF-8" ?>
 <paths xmlns:android="http://schemas.android.com/apk/res/android">
     <external-path name="my_images" path="Android/data/com.yourcompany.XamarinFormsCamera/files/Pictures" />
 </paths>

For more details, you can check:
https://developer.android.com/reference/android/support/v4/content/FileProvider#ProviderDefinition

https://github.com/xamarin/Essentials/issues/130


Best Regards,

Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.


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.



· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Jessie,


Thanks for your answer.

Both AndroidManifest.xml as well as the file_paths.xml file were populate with the info you mentioned.
Your answer along with the two links helped me however to resolve the problem.



Best Regards,

Luk Vandevyvere

0 Votes 0 ·