locked
i need help with this error in plugin.media RRS feed

  • Question

  • User370547 posted

    only one operation can be active at a time xamarin

    this is the code :

     public async void Agregar_Clicked(object sender, EventArgs e)
        {
            var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
            var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
    
            if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });
                cameraStatus = results[Permission.Camera];
                storageStatus = results[Permission.Storage];
            }
    
            if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
            {
                var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name = "test.jpg"
                });
            }
            else
            {
                await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");
            }
    
        }
    
    Tuesday, August 7, 2018 9:24 PM

All replies

  • User369978 posted

    We should not execute two Task at the same time .

    I think it caused by the task RequestPermissionsAsync and TakePhotoAsync.

    Change

    if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)

    to

    else if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)

    Wednesday, August 8, 2018 2:32 AM