diff --git a/MediaGallery/MediaGallery.csproj b/MediaGallery/MediaGallery.csproj index b0bc1ea..c18c9d2 100644 --- a/MediaGallery/MediaGallery.csproj +++ b/MediaGallery/MediaGallery.csproj @@ -10,10 +10,10 @@ Xamarin.MediaGallery This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices $(AssemblyName) ($(TargetFramework)) - 1.0.2.1 - 1.0.2.1 - 1.0.2.1 - 1.0.2.1 + 1.0.2.2 + 1.0.2.2 + 1.0.2.2 + 1.0.2.2-preview1 dimonovdd dimonovdd https://github.com/dimonovdd/Xamarin.MediaGallery diff --git a/MediaGallery/MediaGallery/PickMedia.android.cs b/MediaGallery/MediaGallery/PickMedia.android.cs index 9cf2f7f..16346d8 100644 --- a/MediaGallery/MediaGallery/PickMedia.android.cs +++ b/MediaGallery/MediaGallery/PickMedia.android.cs @@ -26,7 +26,7 @@ static async Task> PlatformPickAsync(MediaPickRequest re { token.ThrowIfCancellationRequested(); Intent intent = null; - Intent chooserIntent = null; + IDisposable intentDisposable = null; try { @@ -62,7 +62,11 @@ static async Task> PlatformPickAsync(MediaPickRequest re if (!string.IsNullOrWhiteSpace(request.Title)) intent.PutExtra(Intent.ExtraTitle, request.Title); - chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty); + if (request.UseCreateChooser) + { + intentDisposable = intent; + intent = Intent.CreateChooser(intent, request.Title ?? string.Empty); + } CancelTaskIfRequested(); @@ -73,7 +77,7 @@ static async Task> PlatformPickAsync(MediaPickRequest re tcs?.TrySetCanceled(token); }); - Platform.AppActivity.StartActivityForResult(chooserIntent, Platform.requestCode); + Platform.AppActivity.StartActivityForResult(intent, Platform.requestCode); CancelTaskIfRequested(false); var result = await tcs.Task.ConfigureAwait(false); @@ -91,10 +95,10 @@ void CancelTaskIfRequested(bool needThrow = true) } finally { + intentDisposable?.Dispose(); + intentDisposable = null; intent?.Dispose(); intent = null; - chooserIntent?.Dispose(); - chooserIntent = null; tcs = null; } } diff --git a/MediaGallery/MediaPickRequest/MediaPickRequest.shared.cs b/MediaGallery/MediaPickRequest/MediaPickRequest.shared.cs index 56f701c..1cf3264 100644 --- a/MediaGallery/MediaPickRequest/MediaPickRequest.shared.cs +++ b/MediaGallery/MediaPickRequest/MediaPickRequest.shared.cs @@ -28,5 +28,8 @@ public MediaPickRequest(int selectionLimit = 1, params MediaFileType[] types) /// Gets or sets the source rectangle to display the Share UI from. This is only used on iPad currently. public Rectangle PresentationSourceBounds { get; set; } = default; + + /// Gets or sets whether to use Intent.CreateChooser. Currently used only for Android. + public bool UseCreateChooser { get; set; } = true; } } diff --git a/README.md b/README.md index 0638c29..9b1a13f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ try var request = new MediaPickRequest(1, MediaFileType.Image, MediaFileType.Video) { PresentationSourceBounds = System.Drawing.Rectangle.Empty, + UseCreateChooser = true, Title = "Select" }; @@ -130,12 +131,14 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int - When using the `PickAsync` method the `selectionLimit` parameter just sets multiple pick allowed - A request to cancel `PickAsync` method will cancel a task, but the picker UI can remain open until it is closed by the user - The use of `Title` property depends on each device +- `UseCreateChooser` specifies whether to use `Intent.CreateChooser` ## iOS - Multi picking is supported since iOS version 14.0+ On older versions, the plugin will prompt the user to select a single file - The `NameWithoutExtension` property on iOS versions before 14 returns a null value if the permission to access photos was not granted - `Title` property not used +- `UseCreateChooser` property not used ### Presentation Location diff --git a/Sample/Sample/App.xaml b/Sample/Sample/App.xaml index 98ceb4b..2577517 100644 --- a/Sample/Sample/App.xaml +++ b/Sample/Sample/App.xaml @@ -45,6 +45,10 @@ + \ No newline at end of file diff --git a/Sample/Sample/ViewModels/PickVM.cs b/Sample/Sample/ViewModels/PickVM.cs index ead9cd6..1bf856b 100644 --- a/Sample/Sample/ViewModels/PickVM.cs +++ b/Sample/Sample/ViewModels/PickVM.cs @@ -37,6 +37,8 @@ public int DelayMilliseconds public string OperationInfo { get; set; } + public bool UseCreateChooser { get; set; } = true; + public IEnumerable SelectedItems { get; set; } public ICommand PickAnyCommand { get; } @@ -73,7 +75,8 @@ void Pick(View view, params MediaFileType[] types) Title = $"Select {SelectionLimit} photos", PresentationSourceBounds = view == null ? System.Drawing.Rectangle.Empty - : view.GetAbsoluteBounds().ToSystemRectangle(40) + : view.GetAbsoluteBounds().ToSystemRectangle(40), + UseCreateChooser = UseCreateChooser }, cts.Token); } diff --git a/Sample/Sample/Views/PickPage.xaml b/Sample/Sample/Views/PickPage.xaml index 629f82e..a3da5fe 100644 --- a/Sample/Sample/Views/PickPage.xaml +++ b/Sample/Sample/Views/PickPage.xaml @@ -18,6 +18,11 @@