0

The first time I use the application after confirming the permission to access the photos saved on the gallery, pickphoto async seems to do nothing. enter image description here

in my opinion the problem is that it does not wait for user authorization.

in order to work correctly I have to click on the upload button of the photo more than once.

i am working with android with the latest version of the library.

await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickPhotoSupported)
{
    await DisplayAlert("Oops", "You Cannot pick an image", AppResources.Label_OK);
    return;
}
var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
{
    PhotoSize = PhotoSize.MaxWidthHeight,
    MaxWidthHeight = 800,
    SaveMetaData = false
});
Fede
  • 9
  • 4
  • 1
    First ensure you have `CAMERA`, `READ_EXTERNAL_STORAGE` and `WRITE_EXTERNAL_STORAGE` permissions added to your AndroidManifest, also ensure to create the `file_provider` profile [check the Media Plugin Readme](https://github.com/jamesmontemagno/MediaPlugin#android-required-setup) and by last i always checks for permissions after the `await CrossMedia.Current.Initialize();` line and before execute the `PickPhotoAsync` and of course both initialization and pick are awaited. – FabriBertani Nov 18 '20 at 01:11

2 Answers2

0

You could ask for the runtime permission before you load the page. After that, you do not need to click on the upload button of the photo more than once.

    protected override void OnAppearing()
{
    base.OnAppearing();
    RunTimePermission();//ask for the runtime permission
}
Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17
0

I thank the people who answered me. I found the error:

Wrong Code:

 public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
    PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

Correct code:

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
Fede
  • 9
  • 4