Mediaplugin: Plugin.Media.Abstractions.MediaPermissionException

Created on 27 Mar 2018  Â·  17Comments  Â·  Source: jamesmontemagno/MediaPlugin

When I debug my app in Android API 19 it works but when I debug in Android API 24 the exception "Plugin.Media.Abstractions.MediaPermissionException: Camera permission (s) is required" is displayed when I want to access the camera and this exception comes out when I want to select a photo from the gallery "Plugin.Media.Abstractions.MediaPermissionException: Storage permission (s) are required".

Bug Information

Version Number of Plugin: 3.1.3
Device Tested On: Samsung Galaxy S7 (API 24), Samsung Galaxy Tab E (API 19)
Simulator Tested On: N/A
Version of VS: 15.6.4
Version of Xamarin: 4.9.0.752
Versions of other things you are using: Xam.Plugin.Connectivity 3.1.1, Xam.Plugins.Settings 3.1.1

Steps to reproduce the Behavior

C

````csharp
private ImageSource imageSource;
private MediaFile file;

private async void prueba(object sender, EventArgs args)
{
await CrossMedia.Current.Initialize();

        if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
        {
            var source = await DisplayActionSheet("¿Donde tomar la imagen?", "Cancelar", null, "Galeria", "Camara");

            switch (source)
            {
                case "Cancelar":
                    file = null;
                    break;
                case "Galeria":
                    file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                    {
                        PhotoSize = PhotoSize.Small
                    });
                    break;
                case "Camara":
                    file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Name = "prueba.jpeg",
                        PhotoSize = PhotoSize.Small,
                        SaveToAlbum = true
                    });
                    break;
                default:
                    break;
            }
        }
        else
        {
            file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
            {
                PhotoSize = PhotoSize.Small
            });
        }

        if (file != null)
        {
            imageSource = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return stream;
            });

            imageProduct.Source = imageSource;
        }
    }

````

AndroidManifest

````xml











android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">

  <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
                   android:resource="@xml/file_paths"></meta-data>
</provider>



````

Most helpful comment

Actually it was my bad. When you install the plugin in Visual Studio it comes up with a comprehensive readme file within VS - once I had faithfully applied all the relevant advice it worked. I think the answer for me was CrossCurrentActivity.Current.Init(this, bundle);

All 17 comments

You don't need to add the permissions in there...
I automatically add Camera/Write External and handle it from there.

The permissions do not add them to me automatically, I have to add them manually in Android to make it work. Is it necessary to install PermissionsPlugin to show me the Android window that the application needs Camera/Write External permissions?

We compile them in at run time, which means you don't need to add them at all.

Else the permission plugin which is installed in this will pop up the dialog boxes for you automatically.

getting Plugin.Media.Abstractions.MediaPermissionException: Camera permission(s) are required when running in Oreo ...

getting Plugin.Media.Abstractions.MediaPermissionException: Camera permission(s) are required when running in Oreo ...

the same to me

Actually it was my bad. When you install the plugin in Visual Studio it comes up with a comprehensive readme file within VS - once I had faithfully applied all the relevant advice it worked. I think the answer for me was CrossCurrentActivity.Current.Init(this, bundle);

Exactly - all perfectly good

Anton Lombard
Framework Systems (Pty) Ltd
[email protected]

On 21 Jan 2019, at 12:15, robedyvean notifications@github.com wrote:

Actually it was my bad. When you install the plugin in Visual Studio it comes up with a comprehensive readme file within VS - once I had faithfully applied all the relevant advice it worked. I think the answer for me was CrossCurrentActivity.Current.Init(this, bundle);

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/jamesmontemagno/MediaPlugin/issues/509#issuecomment-456020112, or mute the thread https://github.com/notifications/unsubscribe-auth/AsGNWgGs_OWwbA_3O_Ou096KLYuLI8ZNks5vFZNdgaJpZM4S9rxZ.

Actually it was my bad. When you install the plugin in Visual Studio it comes up with a comprehensive readme file within VS - once I had faithfully applied all the relevant advice it worked. I think the answer for me was CrossCurrentActivity.Current.Init(this, bundle);

I was getting the similar issue. It is working now. My issue was a messing up path name... so noob :)

"Actually it was my bad. When you install the plugin in Visual Studio it comes up with a comprehensive readme file within VS - once I had faithfully applied all the relevant advice it worked. I think the answer for me was CrossCurrentActivity.Current.Init(this, bundle);"

I've done the same but specifically for using the camera it fails with "Plugin.Media.Abstractions.MediaPermissionException: Contacts permission(s) are required." CrossCurrentActivity.Current.Init(this, bundle); is working as for other permissions like viewing gallery it's fine.

I've asked for permission in the code, accepted on the screen. Also updated the manifest with, camera, storage, contacts and a few others i already use.

Any ideas?

Hi,
After adding the required Permissions in Android for CAMERA, Read/Write External Storage, either in AndroidManifest.xml or at Android Project>>Properties>>Android Manifest>>Required Permissions; then make sure to enable the permission from your Device/Emulator itself:
go to your Device or Emulator then Sittings>>search for Permission>> App Permissions>> Camera>>then Enable your deployed App to use Camera.
Appreciated...

I'm really stuck on this. I have gone throught the steps over and over and I'm still getting the same error. Not sure what to do next,
"Plugin.Media.Abstractions.MediaPermissionException: Camera permission(s) are required."
My Device is running Android 7.1 I looked at each file in the sample and it is implemented the same way.

It's been a while since I solved the problem but I do not remember how I solved it. I remember that I installed a plugin called Permissions Plugin for Xamarin and followed the steps indicated by James. In the file MainActivity.cs of the Android project modify the following line:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.Init(this, bundle);

for this:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

Because I produced compilation errors by other James plugins. Finally I was uploading the minimum API version to 19 (I recommend programming from API 21).

Another factor that is possible is that when compiling in Debug mode, you should put in Release mode when compiling, because in my case when compiling in Debug mode it did not show the window to accept permissions. (Check)

It's been a while since I solved the problem but I do not remember how I solved it. I remember that I installed a plugin called Permissions Plugin for Xamarin and followed the steps indicated by James. In the file MainActivity.cs of the Android project modify the following line:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.Init(this, bundle);

for this:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

Because I produced compilation errors by other James plugins. Finally I was uploading the minimum API version to 19 (I recommend programming from API 21).

This worked for me

It's been a while since I solved the problem but I do not remember how I solved it. I remember that I installed a plugin called Permissions Plugin for Xamarin and followed the steps indicated by James. In the file MainActivity.cs of the Android project modify the following line:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.Init(this, bundle);

for this:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

Because I produced compilation errors by other James plugins. Finally I was uploading the minimum API version to 19 (I recommend programming from API 21).

Thanks for this, It started working all of a sudden. I did move the whole solution to another location and added it to git. Maybe there was something weird with the files

It's been a while since I solved the problem but I do not remember how I solved it. I remember that I installed a plugin called Permissions Plugin for Xamarin and followed the steps indicated by James. In the file MainActivity.cs of the Android project modify the following line:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity.Init(this, bundle);

for this:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

Because I produced compilation errors by other James plugins. Finally I was uploading the minimum API version to 19 (I recommend programming from API 21).

Another factor that is possible is that when compiling in Debug mode, you should put in Release mode when compiling, because in my case when compiling in Debug mode it did not show the window to accept permissions. (Check)

Good Job

CrossCurrentActivity.Current.Init(this, bundle)
Works for my! Thanks @robedyvean

this plugin generates errors on all sides

Was this page helpful?
0 / 5 - 0 ratings