From 50946a78dd5d6a15e9059e2b5f556ecd16acdbfe Mon Sep 17 00:00:00 2001 From: Dima Dimov Date: Sun, 19 Dec 2021 00:46:29 +0300 Subject: [PATCH] fixed capture photo with linker (#86) --- MediaGallery/MediaGallery.csproj | 1 + MediaGallery/MediaGallery/PickMedia.android.cs | 2 +- MediaGallery/Platform/Platform.android.cs | 12 ++++++++++++ MediaGallery/Resources/xml/file_provider_paths.xml | 4 ++++ Xamarim.MediaGallery.targets | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 MediaGallery/Resources/xml/file_provider_paths.xml diff --git a/MediaGallery/MediaGallery.csproj b/MediaGallery/MediaGallery.csproj index 7b16571..f80654f 100644 --- a/MediaGallery/MediaGallery.csproj +++ b/MediaGallery/MediaGallery.csproj @@ -69,6 +69,7 @@ + diff --git a/MediaGallery/MediaGallery/PickMedia.android.cs b/MediaGallery/MediaGallery/PickMedia.android.cs index a9dbba3..a517794 100644 --- a/MediaGallery/MediaGallery/PickMedia.android.cs +++ b/MediaGallery/MediaGallery/PickMedia.android.cs @@ -82,7 +82,7 @@ static async Task PlatformCapturePhotoAsync(CancellationToken token) using var file = new File(tempFilePath); if (!file.Exists()) file.CreateNewFile(); - outputUri = FileProvider.GetUriForFile(Platform.AppActivity, Platform.AppActivity.PackageName + ".fileProvider", file); + outputUri = MediaFileProvider.GetUriForFile(Platform.AppActivity, file); intent.PutExtra(MediaStore.ExtraOutput, outputUri); CancelTaskIfRequested(token, tcsCamera); diff --git a/MediaGallery/Platform/Platform.android.cs b/MediaGallery/Platform/Platform.android.cs index 0b94040..5d54c7e 100644 --- a/MediaGallery/Platform/Platform.android.cs +++ b/MediaGallery/Platform/Platform.android.cs @@ -1,6 +1,8 @@ using Android.App; using Android.Content; using Android.OS; +using AndroidUri = Android.Net.Uri; +using ContentFileProvider = AndroidX.Core.Content.FileProvider; namespace NativeMedia { @@ -39,4 +41,14 @@ internal static bool IsIntentSupported(Intent intent) } } + + [ContentProvider(new[] { "${applicationId}" + Authority },Name = "haraba.fileProvider", Exported = false, GrantUriPermissions = true)] + [MetaData("android.support.FILE_PROVIDER_PATHS", Resource = "@xml/file_provider_paths")] + public class MediaFileProvider : ContentFileProvider + { + internal const string Authority = ".mediaFileProvider"; + + internal static AndroidUri GetUriForFile(Context context, Java.IO.File file) + => GetUriForFile(context, context.PackageName + Authority, file); + } } diff --git a/MediaGallery/Resources/xml/file_provider_paths.xml b/MediaGallery/Resources/xml/file_provider_paths.xml new file mode 100644 index 0000000..f2d4207 --- /dev/null +++ b/MediaGallery/Resources/xml/file_provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Xamarim.MediaGallery.targets b/Xamarim.MediaGallery.targets index 06030ab..ff5d7cb 100644 --- a/Xamarim.MediaGallery.targets +++ b/Xamarim.MediaGallery.targets @@ -3,7 +3,7 @@ <_UseNuget>true <_UseNuget Condition="'$(Configuration)'=='Release'">true - <_LibVersion>2.1.0 + <_LibVersion>2.1.1 <_PermissionLibVersion>2.0.0 <_IsSample Condition="'$(_IsSample)'!='false'">true <_NET6 Condition=" $(TargetFramework.StartsWith('net6')) ">true