dimonovdd / Xamarin.MediaGallery

This plugin is designed to picking and save images and video files from native gallery of Android and iOS devices and capture photos
MIT License
148 stars 18 forks source link

Unable to pick photos from Gallery on Android #93

Closed joeykang closed 1 year ago

joeykang commented 2 years ago

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

dimonovdd commented 2 years ago

Hi 1) Have you tested this on a real device or simulator? 2) Can you provide a sample?

joeykang commented 2 years ago

Hi

  1. Have you tested this on a real device or simulator?
  2. Can you provide a sample?
  1. Yes I tested it on real device, Google Pixel 3a(API 30).
  2. This is the snippet to get photo from the device. if clause did not get caught when selecting a photo from Photos(app). As you see in the screenshot, 'results' and 'capturedPhotos' variables were not null. But it gets photos correctly from other places like 'Download' folder.

                    var results = await MediaGallery.PickAsync(1, MediaFileType.Image); // Allow only one selection
                    capturedPhotos = results?.Files?.ToArray();
    
                    if (capturedPhotos != null && capturedPhotos.Count() == 1)
                    {
                        filePath = await LoadPhotoAsync(capturedPhotos[0]);
                        capturedPhotos[0].Dispose();
                    }

Updates: Got the same issue on Android emulator(API 30)

dimonovdd commented 2 years ago

I can't reproduce this issue. Can you send me a small sample project?

joeykang commented 2 years ago

I can't reproduce this issue. Can you send me a small sample project?

I tested it again with a small sample app and this issue was not happening. I compared related codes between the sample app and my app but I could not find any significant differences. Only thing I observed was OnActivityResult() got called with resultCode 'cancelled' in my app. Whereas, for the sample, OnActivityResult() returns with resultCode 'ok'. This means, in my app, picking a photo from Photos makes OnActivityResult() with failed Result. Any ideas?

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);
}
dimonovdd commented 2 years ago

Maybe there are differences in project settings? AndroidManifest, csproj and etc.

smalgin commented 2 years ago

I found some time & made a sample!

Very interesting bug: Pick from local files works fine, but when I try to pick from Google Drive, everything is gray. Xamarin.Essentials image picker works without any extra steps.

Repro steps: 1) VS 2019

2) provided project

3) Set up Emulator as shown (Essentially Pixel/R/30 with 4GB RAM and forced GPU) image

4) set up Google account there & make sure you have some images in your Google Drive app

5) Try to pick image from Drive. All is gray, you can only pick 'cancel'.

NOTE: Picking from Google Photos works!

MediaGallery.zip

smalgin commented 2 years ago

Good user, I deserve a cookie! :)

dimonovdd commented 2 years ago

Try to pick image from Drive. All is gray, you can only pick 'cancel'.

https://github.com/dimonovdd/Xamarin.MediaGallery/issues/87#issuecomment-1006673216

dimonovdd commented 2 years ago

I have closed this issue, Discussions related to Google Drive will be discussed in a separate issue: #87

joeykang commented 2 years ago

Maybe there are differences in project settings? AndroidManifest, csproj and etc.

Tried changes for AndroidManifest.xml, csproj and AssemblyInfo.cs but no luck. Frustrating.

dimonovdd commented 2 years ago

Maybe can you give me access to your project?

joeykang commented 2 years ago

Maybe can you give me access to your project?

Sorry it's not open project.

matthewyoungias commented 1 year ago

Same issue when moving to API 30 from 29. It worked before doing this.

dimonovdd commented 1 year ago

@matthewyoungias Can you give a sample project?

dimonovdd commented 1 year ago

need more information