Git Product home page Git Product logo

xamarin.mediagallery's Introduction

MediaGallery for Xamarin and MAUI

header

NuGet Badge NuGet downloads license Xamarin.MediaGallery on fuget.org YouTube Video Views

This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices and capture photo.

"Buy Me A Coffee"

FAQ

Please read this file and see samples before creating an issue.

A: Sorry, it became very difficult after adding support for MAUI, but you can build Xamarim.MediaGallery.Sample.sln or Xamarim.MediaGallery.Sample.Maui.sln

A: This is correct behavior. The plugin returns images without any changes, See metadata

A: It is not possible. But you can copy a file to a cache directory

A: Fine! But you need to initialize the plugin on iOS. See taht sample code

A: This issue is on Apple side

Available Platforms

Platform Minimum OS Version
Android 5.0
iOS 11.0

TargetFrameworks

  • net6.0-ios, net6.0-android31.0, net6.0-android32.0, net6.0-android33.0
  • netstandard2.0, Xamarin.iOS10, MonoAndroid10.0, MonoAndroid11.0, MonoAndroid12.0, MonoAndroid13.0

Getting started

You can just watch the Video that @jfversluis published

Migration to 2.X.X version

Android

In the Android project's MainLauncher or any Activity that is launched, this plugin must be initialized in the OnCreate method:

protected override void OnCreate(Bundle savedInstanceState)
{
    //...
    base.OnCreate(savedInstanceState);
    NativeMedia.Platform.Init(this, savedInstanceState);
    //...
}

iOS (Optional)

In the iOS project's AppDelegate that is launched, this plugin can be initialized in the FinishedLaunching method:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    NativeMedia.Platform.Init(GetTopViewController);
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());
    return base.FinishedLaunching(app, options);
}

public UIViewController GetTopViewController()
{
    var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;

    if (vc is UINavigationController navController)
        vc = navController.ViewControllers.Last();

    return vc;
}

PickAsync

This method does not require requesting permissions from users

var cts = new CancellationTokenSource();
IMediaFile[] files = null;

try
{
    var request = new MediaPickRequest(1, MediaFileType.Image, MediaFileType.Video)
    {
        PresentationSourceBounds = System.Drawing.Rectangle.Empty,
        UseCreateChooser = true,
        Title = "Select"
    };

    cts.CancelAfter(TimeSpan.FromMinutes(5));

    var results = await MediaGallery.PickAsync(request, cts.Token);
    files = results?.Files?.ToArray();
}
catch (OperationCanceledException)
{
    // handling a cancellation request
}
catch (Exception)
{
    // handling other exceptions
}
finally
{
    cts.Dispose();
}


if (files == null)
    return;

foreach (var file in files)
{
    var fileName = file.NameWithoutExtension; //Can return an null or empty value
    var extension = file.Extension;
    var contentType = file.ContentType;
    using var stream = await file.OpenReadAsync();
    //...
    file.Dispose();
}

This method has two overloads:

  • Task<MediaPickResult> PickAsync(int selectionLimit = 1, params MediaFileType[] types)
  • Task<MediaPickResult> PickAsync(MediaPickRequest request, CancellationToken token = default)

Android

To handle runtime results on Android, this plugin must receive any OnActivityResult.

protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
{
   if (NativeMedia.Platform.CheckCanProcessResult(requestCode, resultCode, intent))
   NativeMedia.Platform.OnActivityResult(requestCode, resultCode, intent);
   
   base.OnActivityResult(requestCode, resultCode, intent);
}

If an app has android:targetSdkVersion="33" or greater new Photo picker will be used if possible.

Default behavior

  • When using PickAsync method 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 property has not been used since version 2.0.0

Photo Picker behavior

  • selectionLimit parameter limits the number of selected media files
  • Title property not used
  • UseCreateChooser property not used

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

When picking files on iPadOS you have the ability to present in a pop over control. This specifies where the pop over will appear and point an arrow directly to. You can specify the location using the PresentationSourceBounds property. Setting this property has the same behavior as Launcher or Share in Xamarin.Essentials.

PresentationSourceBounds property takes System.Drawing.Rectangle for Xamarin or Microsoft.Maui.Graphics.Rect for .net6(MAUI)

Screenshots:

Сapture Photo with Metadata

//...
if (!MediaGallery.CheckCapturePhotoSupport())
    return;

var status = await Permissions.RequestAsync<Permissions.Camera>();

if (status != PermissionStatus.Granted)
    return;

using var file = await MediaGallery.CapturePhotoAsync()

NameWithoutExtension will always return $"IMG_{DateTime.Now:yyyyMMdd_HHmmss}" value.

Android

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node.

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

If Camera is not required in your application, you can specify false.

<queries>
  <intent>
    <action android:name="android.media.action.IMAGE_CAPTURE" />
  </intent>
</queries>

iOS

In your Info.plist add the following keys:

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>

SaveAsync

//...
var status = await Permissions.RequestAsync<SaveMediaPermission>();

if (status != PermissionStatus.Granted)
    return;

await MediaGallery.SaveAsync(MediaFileType.Video, filePath);

//OR Using a byte array or a stream

await MediaGallery.SaveAsync(MediaFileType.Image, stream, fileName);

//The name or the path to the saved file must contain the extension.

//...

Permission

Add Xamarin.MediaGallery.Permision or Xamarin.MediaGallery.Permision.Maui nuget package to use the SaveMediaPermission

Android

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node.

<!-- for saving photo/video -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • When saving media files, the date and time are appended to the file name

iOS

In your Info.plist add the following keys:

<!-- for saving photo/video on iOS 14+ -->
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos</string>

<!-- for saving photo/video on older versions -->
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos</string>

Screenshots

iOS Android - Defult Android - Photo Picker
iOS Android Android2

xamarin.mediagallery's People

Contributors

catchertinator avatar dimonovdd avatar imgbot[bot] avatar imgbotapp avatar pictos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xamarin.mediagallery's Issues

Issue with SaveAsync permissions on Android 13+

Description

When requesting the SaveMediaPermission on Android 13+ (project targeting Android 13 and device running android 13), I am unable to get a response. My understanding is that the WRITE_EXTERNAL_STORAGE permission check shouldn't be needed on Android 13 and should be skipped, however doing that means the SaveAsync method fails for not having the permission supplied.

Actual Behavior

SaveMediaPermission never gets granted, dialogue doesn't show. SaveAsync errors for denied permission.

Expected behavior

On Android 13 the SaveAsync process should proceed without the SaveMediaPermission (WRITE_EXTERNAL_STORAGE)

Steps to reproduce the behavior

Screenshots or Videos

Reproduction Link

Configuration

  • Device:
  • OS Version:
  • Plugin Version:
  • Framework: Xamarin or MAUI

Initializer is not accessible on Android platform

Description

I'm triying to initialize the plugin and is not accessible for Xamarin.Android from MainActivity.

Screenshots or Videos

Screenshot 2022-11-10 at 17 12 46

Configuration

  • Device: Android
  • OS Version: Any
  • Plugin Version: 2.1.1
  • Framework: Xamarin.Forms 4.8 .NET 6.0.5

Documentation or any pointers for building the project

Hey @dimonovdd ,
I'd like to make some changes to Xamarin.MediaGallery (see #122) regarding the differences between iOS and Android and how they handle albums. I think the changes should be quite simple, but currently I am unable to build the project.

I am using macOS + Visual Studio 2022. I am able to build and deploy both Xamarim.MediaGallery.Sample and Xamarim.MediaGallery.Sample.Maui but it appears that in both instances Xamarim.MediaGallery.targets is forcing those projects to use the nugets (see the _UseNuget here).

Changing _UseNuget to be false I would hope that it would then use the csproj files and build from source but there appears to be issues with it generating NativeMedia.dll. Poking around at this for an hour I was not able to find a resolution.

I then changed tactic and made a new Xamarin.Forms project and added source for Permission and MediaGallery to my solution and tried to get it to build from source that way to no avail.

Third tactic I tried was to build the project manually with msbuild, but building just resulted in compilation errors no matter how I tired to build and what I tried to target.

Is there any info you can provide on how you build it from source. I can see from your comment here that you were building from cli.
I am more than happy to build on cli and manually dump dlls in my test project to test the new code out before I update the samples and send it all off as a PR.

IMediaFile doesn't include the FullPath

Description

It is not possible to get the path where the file(s) where selected

Actual Behavior

IMediaFile doesn't include the FullPath

Expected behavior

Have the FullPath or at least the Path, it makes the plugin unusable sine how are you going to access the file later, you will need the FullPath

Steps to reproduce the behavior

  1. Select a file (PickAsync)
  2. Inspect IMediaFile collection returned
  3. IMediaFile doesn't contain the path of the file

Screenshots or Videos

N/A

Reproduction Link

N/A

Configuration

  • Device: Any
  • OS Version: Any
  • Plugin Version: 1.0.0

Enable SourceLink

<PropertyGroup>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

CapturePhotoAsync not doing anything on iOS

Description

When I call await MediaGallery.CapturePhotoAsync() nothing happens.

A bit more strange than that though - I have a common class which calls MediaGallery. Calling it from one page works fine (so I know the code works). But calling it from a different page doesn't.

The method I call is below. It gets as far as await MediaGallery.CapturePhotoAsync(). I see nothing happening when I execute this line. I can't see any exceptions or anything - the call just never returns.

        public async Task<bool> TakePhoto(string fileName, int? downsize = null)
        {
            bool result = false;
            CameraResults = new List<CameraResult>();

            try
            {
                if (MediaGallery.CheckCapturePhotoSupport())
                {
                    var status = await Permissions.RequestAsync<Permissions.Camera>();

                    if (status != PermissionStatus.Granted)
                        return false;

                    using (IMediaFile file = await MediaGallery.CapturePhotoAsync()) // Doesn't get past here
                    {
                        if (file != null)
                        {

Actual Behavior

Nothing happens

Expected behavior

Camera should open

Steps to reproduce the behavior

  1. Implement the above code
  2. Not sure why it works on one page but not the other so hard to advise what other steps to take.

Screenshots or Videos

Reproduction Link

Configuration

  • Device: iPhone 13
  • OS Version: ios16.3.1
  • Plugin Version: Latest
  • Framework: MAUI

App Crashes when I take 150+ photos using CapturePhotoAsync() in IOS platform .

Description

we are using this nuget in Xamarin.ios application. Our application is a Fleet management application where we used to do inspection for multiple vehicle tires . While doing inspection we take multiple photos for tires (around 200 photos for one vehicle). While doing so the app crashes in "await MediaGallery.CapturePhotoAsync()". we are unable to handle this exception and even the crash log is not reported in Testflight. Due to this crash we are losing the inspection data and user need to do inspection again. Appreciate the help to fix this issue soon.

Actual Behavior

App Should not crash.

Expected behavior

App crashes in iPad Pro (120 photos) , Iphone XR (around 300 photos), iPhone 11 Pro (400 photos)

Code snippet

try
{
    var photo = await MediaGallery.CapturePhotoAsync();

    string photoPath = await SavePhotoLocallyAsync(photo, directory);

    var options = new CompressImageOptions
    {
        CompressionQuality = this.GetCompressionQuality(photoResolution)
    };

    //Android throws a "java.lang.RuntimeException: Canvas: trying to draw too large bitmap" exception when taking pictures on 64MP phones.
    //Added a MaxWidthHeight constraint to control max resolution.
    if (ApplicationHelper.SelectedPlatform == ApplicationHelper.ApplicationPlatform.Android)
    {
        const int SIXTEEN_MEGAPIXEL_WIDTH = 4920;
        options.PhotoSize = PhotoSize.MaxWidthHeight;
        options.MaxWidthHeight = SIXTEEN_MEGAPIXEL_WIDTH;
    }

    await this.compressImageService.ResizeAndCompressImage(photoPath, options);

    photo.Dispose();

    return photoPath;
}
catch(Exception ex)
{
    throw ex;
}

Steps to reproduce the behavior

Screenshots or Videos

Reproduction Link

Configuration

  • Device:Ipad Pro , iPhone XR, Iphone 11 pro, iPhone se (almost all iOS devices we tested).
  • OS Version: 15.0.1,
  • Plugin Version: xamarin.MediaGallery 2.1.1

Support .net standard 2.0

Summary

Since UWP projects doesn't support .net standard 2.1, it would be great if this library could support ,net standard 2.0. Otherwise all xamarin forms setups including UWP will be out of scope, regardless if this picking functionality is to be used by UWP or not.

Album creation when saving assets

Summary

I find it odd that the project will create an album when saving data on Android but not with iOS. Currently there is no functionality to enable this behaviour.

I believe I can make these changes but I am currently unable to build the project from source (see #121).

API Changes

For all of the SaveAsync methods a new argument is added which indicates an album name to be used and/or created.

public static async Task SaveAsync(MediaFileType type, Stream fileStream, string fileName, string album = null)

It should be defaulted to null which will mean there are no breaking changes going forwards and the code would retain the same results (Android generates albums based on app name, iOS does not generate an album).

If an empty string is given then no album is created and the asset is saved in the root gallery/photo/video location.

If a string is provided then it will be used in place of albumName in Android and new code will be added on iOS to create the album. As far as I know no additional iOS permissions are required and I already have existing code to create albums on iOS so I should be able to plop that in.

I am unaware if there are issues of not saving to an album on Android and if that is why the app is made that way.

Unable to pick photos from Gallery on Android

Description

Unable to pick photos from Gallery(Photos app) on Android. But picking photos from other places like Download works correctly.

Actual Behavior

If I pick a photo from Gallery(Photos app) it returns empty result, not crash.

Expected behavior

It should return selected photo as a result.

Steps to reproduce the behavior

  1. Call PickAsync()
  2. call results?.Files?.ToArray();

Screenshots or Videos

image

Reproduction Link

Configuration

  • Device: Google Pixel 3a
  • OS Version: Android 30
  • Plugin Version: 2.1.1
  • Framework: Xamarin or MAUI: Xamarin

Setting size and quality options when picking

Summary

When using the legacy CrossMedia plugin, you have the ability to define image max width/height and compressionQuality. Are there any plans to implement this kind of functionality?

API Changes

Perhaps looking at CrossMedia.Current.PickPhotoAsync could give some inspiration

Bad image rotation

First I take image with phone camera , image is in good orientation. Then after uploading same image inside the app orientation is not good . Any idea how to fix this .
I'm testing this on Android

Actual Behavior

Expected behavior

Steps to reproduce the behavior

Screenshots or Videos

Reproduction Link

Configuration

  • Device: Android
  • OS Version: 11
  • Plugin Version: 2.1.1
  • Framework: Xamarin or MAUI : Xamarin Forms

Unable to pick photos from Gallery on iOS simulator

Description

I'm able to pick photos from Gallery when running on iOS simulator.

Actual Behavior

OpenReadAsync() throws an exception like below.

Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x600002006a90 {Error Domain=NSCocoaErrorDomain Code=256 "The file “version=1&uuid=B84E8479-475C-4727-A4A4-B77AA9980897&mode=compatible.jpeg” couldn’t be opened." UserInfo={NSURL=file:///Users/joey/Library/Developer/CoreSimulator/Devices/D004FFB9-AEC8-46F5-BDCE-67F4392FF633/data/Containers/Shared/AppGroup/40F09F17-AF44-4239-A0B8-B26FC04C9BD9/File%20Provider%20Storage/photospicker/version=1&uuid=B84E8479-475C-4727-A4A4-B77AA9980897&mode=compatible.jpeg, NSFilePath=/Users/joey/Library/Developer/CoreSimulator/Devices/D004FFB9-AEC8-46F5-BDCE-67F4392FF633/data/Containers/Shared/AppGroup/40F09F17-AF44-4239-A0B8-B26FC04C9BD9/File Provider Storage/photospicker/version=1&uuid=B84E8479-475C-4727-A4A4-B77AA9980897&mode=compatible.jpeg, NSUnderlyingError=0x60000207f8a0 {Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)"}}}}

Expected behavior

Stream should be returned with OpenReadAsync()

Steps to reproduce the behavior

  1. await MediaGallery.PickAsync()
  2. OpenReadAsync()

Screenshots or Videos

Reproduction Link

Configuration

  • Device: iPhone 12 mini simulator
  • OS Version: iOS 15.2
  • Plugin Version: 2.1.1
  • Framework: Xamarin 5
  • Xcode: 13.2.1

.NET 6, Maui and VS 17.3.2

Description

Won't work with .NET 6 and latest VS Maui release

Actual Behavior

When trying to run on the Android emulator, I get this error

Error java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: *****nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.9\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar : com/google/common/util/concurrent/ListenableFuture.class SeeingAI.Android C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.415\tools\Xamarin.Android.D8.targets 79

Which I was able to fix by following this thread xamarin/AndroidX#595

But, when I run MediaGallery.PickAsync, I get the following exception

Could not resolve type with token 0100005c from typeref (expected class 'Microsoft.Maui.Essentials.Platform' in assembly 'Microsoft.Maui.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null')

Configuration

  • Device: Android
  • OS Version: Any
  • Plugin Version: 2.1.1
  • Framework: MAUI .NET 6

Incorrect behavior on Xiaomi and other androids

Description

There are cases when using Intent.ACTION_PICK or Intent.createChooser() on some devices, the picker does not return the files selected by a user. It has already been partially solved in Pull Request #61.

But I plan to use only Intent.ACTION_GET_CONTENT by deleting everything related toIntent.ACTION_PICK or Intent.createChooser()

MediaPickResult.Files return a wrong selection order on Android

Description

My application will ask user to pick some images and put those images on a canvas while maintaining the order they choose.

Everything work perfectly on iOS, "MediaPickResult.Files" return the images using the order that user select.
But on Android it seems always return images using a different order instead of the order when user make selection.

Actual Behavior

MediaPicker

When user select images using order such as [6, 9, 13, 1] or [1, 13, 6, 9] or [6, 1, 13, 9].
MediaPickResult.Files always return images using order [13, 1, 9, 6].

Expected behavior

Return the images using the same order as user select [6, 9, 13, 1] or [1, 13, 6, 9] or [6, 1, 13, 9].

Configuration

  • Device: Android Emulator (Pixel 5 - Android 13 - API 33),
  • OS Version: Android 13
  • Plugin Version: Latest
  • Framework: MAUI

GPS metadata of images taken with the CapturePhotoAsync method is set to 0.

Description

Images taken using the CapturePhotoAsync method do not contain GPS information.

The info.plist describes the permissions for using the camera and location information.

I am not familiar with development on iOS.
I don't know if the plugin is the cause.
Any advice would be appreciated.

Expected behavior

Latitude and longitude of the shooting location are included in the meta data.

Steps to reproduce the behavior

if (!MediaGallery.CheckCapturePhotoSupport())
    return;

var status = await Permissions.RequestAsync<Permissions.Camera>();

if (status != PermissionStatus.Granted)
    return;

using (var file = await MediaGallery.CapturePhotoAsync())
{
    var stream = await file.OpenReadAsync();
    var exif = ExifReader.ReadJpeg(stream);
}

Screenshots or Videos

スクリーンショット 2022-08-15 14 26 06

Configuration

  • Device: iPhone 13 mini
  • OS Version: 15.6
  • Plugin Version: 2.1.1
  • Framework: Xamarin.Forms

Cannot pick files from Google Drive

Description

Picker opens, I get intent popups, tapped Allow, then selected Google Drive. All image files are grayed out.

Expected behavior

Able to pick up files from Google Drive. Xamarin.Essentials picker can do it.

Configuration

  • Device: Galaxy Tab A SM-510
  • OS Version: Android 11, One UI 3.1
  • Plugin Version: latest

Merge MediaGallery and Permission packages

Summary

There may be a very good reason for this, but I don't understand why there is a base Xamarin.MediaGallery package, and then also
Xamarin.MediaGallery.Permision and Xamarin.MediaGallery.Permision.Maui packages.

I first thought it was so you wouldn't have to take on a dependency of Xamarin.Essentials but it appears that both Xamarin.Essentials and Xamarin.MediaGallery.Permission* are dependencies of Xamarin.MediaGallery (at least that's how it looks according to this.

I think removing it as a seperate project may simplify things a tad. If you are ok with this I can make the change on a branch that I have which is a branch off feature/custom_albums where I have done some project organisation updates (uncommitted currently).

API Changes

Deprecate Xamarin.MediaGallery.Permision nuget package.
Deprecate Xamarin.MediaGallery.Permision.Maui nuget package.
All code references should work fine as they use the root namespace of NativeMedia. If people have these additional nugets installed manually they will have to remove them which may be considered a breaking change but I can make sure its documented.

iOS 15 - Pick photo 'Add' and 'Cancel' button text not visible

Description

Recently converted to using this plugin instead of the MediaPlugin (https://github.com/jamesmontemagno/MediaPlugin) for taking and selecting photos.

After the transition, I noticed that when picking a photo on iOS 15 devices, the 'Add' and 'Cancel' button text color is white and the popover background color is also white, which results in the buttons being essentially invisible to the user.

image

I've noticed that if you scroll through the photos you can sometimes then see the text because the background is no longer white.

image

I thought it was related to an outdated Xamarin.Forms nuget package but I upgraded to the latest Xamarin.Forms package, 5.0.0.2337, and noticed the issue persists. I checked my code and was not immediately able to come across anything that seemed to be overriding the button text color used in the popover...but I will continue to see if an override in my code might be the culprit.

I'm curious if anyone else has encountered this issue and if so, might be aware of a solution?

Actual Behavior

Text color in Popover used for photo selection is white and the background is also white, making the text 'invisible' to the user.

Expected behavior

Text color in Popover would be a color other than white (the background color)

Steps to reproduce the behavior

N/A

Screenshots or Videos

(in description)

Reproduction Link

N/A

Configuration

  • Device: iPhone or iPad
  • OS Version: 15+
  • Plugin Version: 2.1.1
  • Framework: Xamarin

Selected file should have a property to hold path of the actual file.

Summary

Whenever we select or pick a media file using MediaGallery.PickAsync(), the result must have a property that holds the path of the actual file we selected. The result is of type MediaPickResult that has a property named Files. This File is IEnumerable<IMediaFile> and IMediaFile has properties listed below:

public interface IMediaFile : IDisposable
{
    string NameWithoutExtension { get; }
    string Extension { get; }
    string ContentType { get; }
    MediaFileType? Type { get; }
    Task<Stream> OpenReadAsync();
}

Hence, as shown, it doesn't have any property showing path of the actual file that we selected. It is much required feature as we can further operate on the picked file like compressing, showing preview such as thumbnails, and for showing video previews. We can also inject Dependency Services for platform specific functions.

The only thing now we can do is copy the stream to a file using Stream.CopyToAsync(). But this creates a duplicate copy of an already existing file. This takes a long time for video files depending on the size. This is not the proper way, it's just a workaround.

Adding a feature to provide file path of the selected file will be much appreciable. Thanks.

Improve getting the current context

Summary

Getting the current activity is not done quite correctly.

public static partial class Platform
{
    static Activity currentActivity;

    internal static Activity AppActivity
         => currentActivity
        ?? throw ExeptionHelper.ActivityNotDetected;
}

Permalink

Maybe we could replace this with a IActivityLifecycleCallbacks or the Android.App.Application.Context

README Sample Code Improvements

Just tried the sample code from the README on iOS and if you've not asked permission before it will never ask permission with this snippet

var status = await Permissions.CheckStatusAsync<SaveMediaPermission>();

if (status != PermissionStatus.Granted)
    return;

await MediaGallery.SaveAsync(MediaFileType.Video, filePath);

The status will be Unknown and it will leave the method before actually asking for permission.

Additionally, it might be good to note that if you try to save without a file extension, i.e.: await MediaGallery.SaveAsync(MediaFileType.Image, "myScreenshot"); there will be an exception.

Great work btw! Making a video on this soon! :)

Code hanging at call to CapturePhotoAsync

Description

When I call this line:
var file = await MediaGallery.CapturePhotoAsync(cts.Token);
The camera shows and I can click the tick, but the following code never gets executed. It is like the await never returns. Reported by another team member and verified same behaviour on my device.

Actual Behavior

Code never executes past this point.

Expected behavior

Code continues to execute.

Steps to reproduce the behavior

  1. Implement example code exactly as is.

Screenshots or Videos

Reproduction Link

Configuration

  • Device: Android emulator
  • OS Version: Android 13
  • Plugin Version: Latest
  • Framework: MAUI

Calling OpenReadAsync on iOS Simulator Throws Exception

Description

After using the PickAsync method, and calling OpenReadAsync on the IMediaFile, an exception is thrown.

Actual Behavior

The exception message is:
Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x600000cd15c0 {Error Domain=NSCocoaErrorDomain Code=256 "The file “version=1&uuid=9610D22F-9061-4690-B523-C334B801D14E&mode=compatible.jpeg” couldn’t be opened." UserInfo={NSURL=file:///Users/jasonwilliams/Library/Developer/CoreSimulator/Devices/9863D3D7-0CDA-4173-9D0D-18F2C2264F08/data/Containers/Shared/AppGroup/15E088FC-FF0D-4673-8551-655BC0777510/File%20Provider%20Storage/photospicker/version=1&uuid=9610D22F-9061-4690-B523-C334B801D14E&mode=compatible.jpeg, NSFilePath=/Users/jasonwilliams/Library/Developer/CoreSimulator/Devices/9863D3D7-0CDA-4173-9D0D-18F2C2264F08/data/Containers/Shared/AppGroup/15E088FC-FF0D-4673-8551-655BC0777510/File Provider Storage/photospicker/version=1&uuid=9610D22F-9061-4690-B523-C334B801D14E&mode=compatible.jpeg, NSUnderlyingError=0x600000cd4840 {Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)"}}}}

When I go look at the path on the mac (/Users/.../photospicker/) I do see the "version=1&uuid=9610D22F-9061-4690-B523-C334B801D14E&mode=compatible.jpeg" file and I can open it from the mac.

Expected behavior

No exception should be thrown.

Steps to reproduce the behavior

Screenshots or Videos

Reproduction Link

Configuration

  • Device: iOS Simulator
  • OS Version: 15.2
  • Plugin Version: 2.1.1
  • Framework: Xamarin

Get errors with a fresh download in VS 17.1.4 and 17.2.0 Preview 3.0

Description

Get errors with a fresh download in VS 17.1.4 and 17.2.0 Preview 3.0 (VS Professional)

I want to see how the Samples run and then determine how our app can use this package.
Currently, I am only interested in the Xamarin Forms Samples so I did not try Maui.

Actual Behavior

Out of the box, I opened Xamarin MediaGallery Samples from VS 17.1.4 and from VS 17.2.0.Preview 3.0. I got the following errors

VS 17.1.4

`Samples

Severity Code Description Project File Line Suppression State
Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with monoandroid11.0 (MonoAndroid,Version=v11.0). Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.Android C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.Android\Sample.Android.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x86. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0). Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x64. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1012 Platform version is not present for one or more target frameworks, even though they have specified a platform: net6.0-ios, net6.0-android Sample.Common C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Common\Sample.Common.csproj 1
Error NU1012 Platform version is not present for one or more target frameworks, even though they have specified a platform: net6.0-ios, net6.0-android Sample.Common C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Common\Sample.Common.csproj 1
Error NU1012 Platform version is not present for one or more target frameworks, even though they have specified a platform: net6.0-ios, net6.0-android Sample.Common C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Common\Sample.Common.csproj 1
Error NU1012 Platform version is not present for one or more target frameworks, even though they have specified a platform: net6.0-ios, net6.0-android Sample.Maui C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\MAUI\Sample.Maui.csproj 1
Error NU1012 Platform version is not present for one or more target frameworks, even though they have specified a platform: net6.0-ios, net6.0-android Sample.Maui C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\MAUI\Sample.Maui.csproj 1
`

VS 17.2.0.Preview 3.0

samples

Severity Code Description Project File Line Suppression State
Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with monoandroid11.0 (MonoAndroid,Version=v11.0). Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.Android C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.Android\Sample.Android.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x86. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0). Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Error NU1202 Package Xamarin.MediaGallery.Permision.Maui 2.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x64. Package Xamarin.MediaGallery.Permision.Maui 2.0.0 supports:

  • net6.0 (.NETCoreApp,Version=v6.0)
  • net6.0-android31.0 (.NETCoreApp,Version=v6.0)
  • net6.0-ios15.0 (.NETCoreApp,Version=v6.0) Sample.iOS C:\Users\wauti\source\repos5\2204\Xamarin.MediaGallery-main\Sample\Xamarin\Sample.iOS\Sample.iOS.csproj 1

Expected behavior

That the app should be able to run without errors in at least one of the versions of VS

Steps to reproduce the behavior

  1. Download a zip
  2. extract the code
  3. open in VS 17.1.4 or VS 17.2.0.Preview 3.0.
  4. see the errors

Screenshots or Videos

Reproduction Link

Configuration

  • Device: n/a (can't get to a device if I can't get past errors)
  • OS Version: See Device. My PC has Win 11.
  • Plugin Version: Xamarin MediaGallery v 2.1.1
  • Framework: Xamarin or MAUI Xamarin Forms

Current features question

Hi there. I maintain an app that relies on the MediaPlugin quite heavily. Since support ceased for this plugin it's been a bit difficult, so I was keen to find out what your project here is doing and what plans you might have for future features. I see that you're also contributing back to Xamarin Essentials which is great.

Does your project currently - or will it in the future - support:

  • Saving metadata with a photo similar to what the old MediaPlugin did with SaveMetaData = true? For my use case, I'm specifically interested in saving EXIF GPS data within a photo.
  • Dealing with the more granular iOS photo permissions for 14+ (i.e. "Select Photos...", "Allow access to all photos" and "Don't allow") - the old MediaPlugin doesn't properly support the newer "Select Photos..." option.
  • Gracefully handling Android gallery apps that only allow a single photo to be picked (e.g. the Samsung Gallery app, last I checked) when selectionLimit is > 1?

These features are pretty central to our app and hacking the MediaPlugin code for myself isn't feeling like a viable long term solution. So I'd be keen to try and help out here if I can, with this kind of stuff.

Result being returned after 1st selected image even though limit is > 1

Description

Task is to select multiple images from Photos/Gallery and when pressed "Done" to return the selected..

Actual Behavior

Configuration

Works as expected on OnePlus 7 Pro (Android 11)
Does not work on Samsung S9 & Note 9 (Both Android 10)
Running same app version/code on all devices (see videos)
Plugin version : 1.0.2.2

Expected behavior

Steps to reproduce the behavior

Screenshots or Videos

https://user-images.githubusercontent.com/6523354/136189156-93d1bb3f-be45-4358-834f-c24590c5eb6f.mp4
https://user-images.githubusercontent.com/6523354/136189161-3f859725-617b-4852-ba32-5df147f7eca5.mp4

Reproduction Link

async void method()
{
var cts = new CancellationTokenSource();
IMediaFile[] files = null;

        try
        {
            var request = new MediaPickRequest(20, MediaFileType.Image)
            {
                PresentationSourceBounds = System.Drawing.Rectangle.Empty,
                UseCreateChooser = true,
                Title = "Select Venue Photos"
            };

            cts.CancelAfter(TimeSpan.FromMinutes(5));

            var results = await MediaGallery.PickAsync(request, cts.Token);
            files = results?.Files?.ToArray();
        }
        catch (OperationCanceledException)
        {
            // handling a cancellation request
        }
        catch (Exception)
        {
            // handling other exceptions
        }
        finally
        {
            cts.Dispose();
        }

}

Cant pick more than 10 images from gallery at once iOS MAUI

Description

I have some users that want to be able to select a lot of photos at once (up to 200). But they are only able to select a maximum of 10. This issue only presents on iOS

Actual Behavior

Can only select 10 photos with a selection limit of 200.

Expected behavior

Should be able to select up to the number in the selection limit

Steps to reproduce the behavior

  1. Set selection limit to a number greater than 10
  2. Try to select that many from gallery
  3. Limited at 10

Screenshots or Videos

Reproduction Link

Configuration

  • Device:
  • OS Version: iOS
  • Plugin Version:
  • Framework: MAUI

Camera app doesn't open on CapturePhotoAsync

Description

Camera app doesn't open on CapturePhotoAsync

Expected behavior

Should open the camera app. Xamarin.Essentials media picker works.

Code snippet

if (MediaGallery.CheckCapturePhotoSupport())
return;

        var status = await Permissions.RequestAsync<Permissions.Camera>();

        if (status != PermissionStatus.Granted)
            return;

        using var photoFile = await MediaGallery.CapturePhotoAsync();

Configuration

  • Device: Galaxy Tab A SM-510
  • OS Version: Android 11, OneUI 3.1
  • Plugin Version: latest

Some comments on the readme file

Description

  1. Not a bug really, but some clarifications to the readme file could be good.
    Under Getting Started, the iOS header says "Optional". and then the text says "this plugin must be initialized in..". Is it optional or does it have to be initialized?

  2. The code sample seems to have a typo.
    public UIViewController GetTopViewController()
    {
    var window = UIApplication.SharedApplication.KeyWindow.RootViewController;

    if (vc is UINavigationController navController)
    vc = navController.ViewControllers.Last();

    return vc;
    }

shouldn't "window" be "vc"?

[iOS] Image picker returns incorrect onrientation, when image was not taken holding phone "90 deg left"

Description

iOS stores images in non rotated and save the rotation compared to the camera in exif data i believe.
When picking with the ImagePicker iOS handles the rotation in the image previews.
This is not taking into consideration when the lib delivers the images picked from gallery.

This seams to be a problem with all multi image pickers for xamarin.forms out there.
But serval people hinted that this one didn't have it, so here is a bug report.

if I'm using the lib. wrong or this is expected behaviour, then don't hesitate to close this again.
im trying to let a user pick some images and the phone uploads them to a server where they are used later.

Actual Behavior

After picking images in gallery and gotten the image with *.OpenReadAsync() they show as if they where all taken with the phone held at "90 deg. left"

Expected behavior

*.OpenReadAsync() returns a image with the expected orientation.

Steps to reproduce the behavior

take images holding the phone ex. upright or 90 deg right.
use MediaGallery.PickAsync to get them
use OpenReadAsync() to get bytes/stream
display image on screen.

Screenshots or Videos

2-edit
3-edit

Reproduction Link

Configuration

  • Device: Xs
  • OS Version: 15.1
  • Plugin Version: 2.1.1
  • Framework: Xamarin

Add the option to cancel pick files

Summary

We could use a CancellationToken to cancel a file pick operation and close picker view.

API Changes

public static async Task<MediaPickResult> PickAsync(int selectionLimit = 1, CancellationToken token = default, params MediaFileType[] types)

SaveAsync not working on iOS or Android

Description

I am having some trouble to get SaveAsync working on iOS and Android. I am trying to take a photo, and then save the photo to the gallery too.

When calling SaveAsync with the path of a photo recently taken using CapturePhotoAsync in the Xamarin.Forms shared project, it throws an exception on both iOS and Android/

Actual Behavior

SaveAsync iOS exception:

{Foundation.NSErrorException: Error Domain=PHPhotosErrorDomain Code=-1 "(null)"
  at NativeMedia.MediaGallery.PhotoLibraryPerformChanges (System.Action action) [0x000ac] in <cb2ee5d4eb154dc9baa4ecea7ba18b93>:0 
  at NativeMedia.MediaGallery.PlatformSaveAsync (NativeMedia.MediaFileType type, System.String filePath) [0x000aa] in <cb2ee5d4eb154dc9baa4ecea7ba18b93>:0 
  at NativeMedia.MediaGallery.SaveAsync (NativeMedia.MediaFileType type, System.String filePath) [0x000f5] in <cb2ee5d4eb154dc9baa4ecea7ba18b93>:0 
  at Inspct.Services.DataService.SaveToGallery (System.String filePath) [0x00106] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\DataService.cs:190 
  at Inspct.Services.DataService.TakeNewPhoto (Inspct.Helpers.GlobalEnums+DataTableTypes tableType, System.Guid sourceID, System.Nullable`1[T] secondaryID, System.String fileName) [0x002b0] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\DataService.cs:141 
  at Inspct.Services.InspectionsService.AddInspectionDataAttachment (Inspct.ViewModels.Inspections.FieldTypes.FieldViewModel fieldViewModel) [0x004c1] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\InspectionsService.cs:999 }

SaveAsync Android exception:

{Java.Lang.IllegalArgumentException: MIME type application/octet-stream cannot be inserted into content://media/external/images/media; expected MIME type under image/*
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <1959115d56f8444789986cf39185638c>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <1959115d56f8444789986cf39185638c>:0 
  at Android.Content.ContentResolver.Insert (Android.Net.Uri url, Android.Content.ContentValues values) [0x00049] in /Users/builder/azdo/_work/2/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Content.ContentResolver.cs:1127 
  at NativeMedia.MediaGallery.PlatformSaveAsync (NativeMedia.MediaFileType type, System.IO.Stream fileStream, System.String fileName) [0x00150] in <04e7edd214f44f6f8ccb9794e517ed6a>:0 
  at NativeMedia.MediaGallery.PlatformSaveAsync (NativeMedia.MediaFileType type, System.String filePath) [0x0008f] in <04e7edd214f44f6f8ccb9794e517ed6a>:0 
  at NativeMedia.MediaGallery.SaveAsync (NativeMedia.MediaFileType type, System.String filePath) [0x000f5] in <04e7edd214f44f6f8ccb9794e517ed6a>:0 
  at Inspct.Services.DataService.SaveToGallery (System.String filePath) [0x00106] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\DataService.cs:190 
  at Inspct.Services.DataService.TakeNewPhoto (Inspct.Helpers.GlobalEnums+DataTableTypes tableType, System.Guid sourceID, System.Nullable`1[T] secondaryID, System.String fileName) [0x002b0] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\DataService.cs:141 
  at Inspct.Services.InspectionsService.AddInspectionDataAttachment (Inspct.ViewModels.Inspections.FieldTypes.FieldViewModel fieldViewModel) [0x004c1] in C:\CODE\CPL\INSPCTXamarinApp\InspctXamarinApp\Inspct\Services\InspectionsService.cs:999 
  --- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: MIME type application/octet-stream cannot be inserted into content://media/external/images/media; expected MIME type under image/*
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
	at android.content.ContentProviderProxy.insert(ContentProviderNative.java:549)
	at android.content.ContentResolver.insert(ContentResolver.java:2149)
	at android.content.ContentResolver.insert(ContentResolver.java:2111)
	at mono.java.lang.RunnableImplementor.n_run(Native Method)
	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7656)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
}

Expected behaviour

The image to be saved to the gallery and not throw an exception.

Steps to reproduce the behaviour

var photo = await MediaGallery.CapturePhotoAsync();
if (photo != null)
{
    string fileName = string.Format("INSPCT_{0}_{1}{2}", photo.NameWithoutExtension, DateTime.Now.Ticks.GetHashCode().ToString("X"), photo.Extension);
    string newFileLocation = Path.Combine(FilesDirectory, fileName);

    using (FileStream fileStream = File.OpenWrite(newFileLocation))
    {
        await (await photo.OpenReadAsync()).CopyToASync(fileStream);
    }
	
    photo.Dispose();

    var status = await Permissions.RequestAsync<SaveMediaPermission>();
    if (status == PermissionStatus.Granted)
    {
        await MediaGallery.SaveAsync(MediaFileType.Image, filePath); // throws exception
    }
}

Screenshots or Videos

Reproduction Link

Configuration

  • Device: iPhone XS Max, Pixel 4, Pixel 3 Simulator
  • OS Version: iOS 14.6, Android 12, Android 11
  • Plugin Version: 2.1.1
  • Framework: Xamarin 4.3.0

On android the selection limit seems not working

Description

I've set selectionLimit to 20 in one of my project, it works fine on iOS but doesn't work on android. Meaning it can allow user to select more then my specified selection limit i.e. 20.
await MediaGallery.PickAsync(20, MediaFileType.Image);

Actual Behavior

It allows user to select more than specified selection limit.

Expected behavior

It should restrict user to select the images as specified in selectionLimit parameter. In my case it should not allow to select more than 20 images

Steps to reproduce the behavior

Screenshots or Videos

Screenshot 2021-10-28 at 1 32 17 AM

Reproduction Link

Configuration

  • Device: Motorola G9
  • OS Version: Android 10
  • Plugin Version:1.0.2.2

Picked image is rotated 90 degrees on Android

Description
When you pick image with PickAsync on Android result image is rotated by 90 degrees.
Same code works fine in iOS.

Expected behavior
Picked image should be displayed in same orientation as it was originally taken e.g. portrait or landscape.

Steps to reproduce the behavior

var request = new MediaPickRequest( 1, MediaFileType.Image )
{
    PresentationSourceBounds = PhotoSize.Full,
    Title = "Select image"
};

var results = await MediaGallery.PickAsync( request );
var file = results?.Files?.ToArray()?.First();

byte[] imageData;
var stream = await file.OpenReadAsync(); 

using (MemoryStream ms = new MemoryStream())
{
    stream.CopyTo( ms );
    imageData = ms.ToArray();
}

return imageData;

Configuration
Device: Samsung S7, Samsung Galaxy Tab A7
OS Version: Android 11
Plugin Version: 2.1.1
Framework: Xamarin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.