Skip to content

Commit

Permalink
fixed capture photo with linker (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimonovdd authored Dec 18, 2021
1 parent b131fc2 commit 50946a7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions MediaGallery/MediaGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<ItemGroup Condition=" '$(_Droid)' == 'true' ">
<Compile Include="**\*.android.*.cs" />
<Compile Include="**\*.android.cs" />
<AndroidResource Include="Resources\xml\*.xml" />
</ItemGroup>
<ItemGroup Condition=" '$(_IOS)' == 'true' ">
<Compile Include="**\*.ios.*.cs" />
Expand Down
2 changes: 1 addition & 1 deletion MediaGallery/MediaGallery/PickMedia.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static async Task<IMediaFile> 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);
Expand Down
12 changes: 12 additions & 0 deletions MediaGallery/Platform/Platform.android.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions MediaGallery/Resources/xml/file_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<paths>
<cache-path name="internal_cache" path="." />
</paths>
2 changes: 1 addition & 1 deletion Xamarim.MediaGallery.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<_UseNuget>true</_UseNuget>
<_UseNuget Condition="'$(Configuration)'=='Release'">true</_UseNuget>
<_LibVersion>2.1.0</_LibVersion>
<_LibVersion>2.1.1</_LibVersion>
<_PermissionLibVersion>2.0.0</_PermissionLibVersion>
<_IsSample Condition="'$(_IsSample)'!='false'">true</_IsSample>
<_NET6 Condition=" $(TargetFramework.StartsWith('net6')) ">true</_NET6>
Expand Down

0 comments on commit 50946a7

Please sign in to comment.