Mediaplugin: Plugin.Media.Abstractions.MediaPermissionException: <Timeout exceeded getting exception details>

Created on 27 Oct 2018  路  6Comments  路  Source: jamesmontemagno/MediaPlugin

Bug Information

Getting the exception, am I missing any plugins? Exception occurs at
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = Environment.GetFolderPath(Environment.SpecialFolder.Personal), Name = "test.jpg" });

Version Number of Plugin: 4.0.1.5
Device Tested On:
Simulator Tested On: Nexus_6_API_28(Android 9.0 - API 28)
Version of VS: 2017
Version of Xamarin: 4.11.0.776
Versions of other things you are using:

Steps to reproduce the Behavior

Click on the button

Expected Behavior

Take Picture

Actual Behavior

Public.Media.Abstraction.MediaPermissionException

Code snippet

`

  using Plugin.Media;
  using Plugin.Media.Abstractions;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Xamarin.Forms;

  namespace CameraAppText
  {
       public partial class MainPage : ContentPage
       {
              public MainPage()
              {
                   InitializeComponent();
                   CameraButton.Clicked += CameraButton_Clicked;
               }

    private async void CameraButton_Clicked(object sender, EventArgs e)
    {

        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await DisplayAlert("No Camera", ":( No camera available.", "OK");
            return;
        }

        var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
        {
            Directory = "Sample",
            Name = "test.jpg"
        });

        if (file == null)
            return;

        await DisplayAlert("File Location", file.Path, "OK");

        PhotoImage.Source = ImageSource.FromStream(() =>
        {
            var stream = file.GetStream();
            return stream;
        });
    }
}
}

`

`
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CameraAppText"
x:Class="CameraAppText.MainPage">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Image x:Name="PhotoImage" />
    <Button x:Name="CameraButton" Text="Take Photo" Grid.Row="1" />
</Grid>

`

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname" android:installLocation="auto"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:label="CameraAppText.Android"></application> </manifest>

Screenshots

screenshot_5

screenshot_6

screenshot_7

Most helpful comment

@vinnusaurus @James-Aidoo I to had this issue both on a physical device and in the emulator. I started digging and tried the following code:

var cameraStatus = await Plugin.Permissions.CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await Plugin.Permissions.CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

The cameraStatus told me that I had granted the app camera permissions but the storageStatus came back as "Denied". I took a look at the code and it turns out that if you don't grant permissions for _both_ camera and storage you will get this exception.

However just adding the permissions in the AndroidManifest.xml file the same exception was still thrown. So i looked at the code for https://github.com/jamesmontemagno/PermissionsPlugin and that code uses the Current Activity Plugin.

So I installed that plugin to the Android project and followed the instructions after that I got a new exception that pointed to this section of the Readme. After following the instructions there it finally worked for me.

Hope this helps!

All 6 comments

In the same situation here when running in an emulator... Works fine on a physical device though

@vinnusaurus @James-Aidoo I to had this issue both on a physical device and in the emulator. I started digging and tried the following code:

var cameraStatus = await Plugin.Permissions.CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await Plugin.Permissions.CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

The cameraStatus told me that I had granted the app camera permissions but the storageStatus came back as "Denied". I took a look at the code and it turns out that if you don't grant permissions for _both_ camera and storage you will get this exception.

However just adding the permissions in the AndroidManifest.xml file the same exception was still thrown. So i looked at the code for https://github.com/jamesmontemagno/PermissionsPlugin and that code uses the Current Activity Plugin.

So I installed that plugin to the Android project and followed the instructions after that I got a new exception that pointed to this section of the Readme. After following the instructions there it finally worked for me.

Hope this helps!

Did you initialize the CurrentActivity Plugin? I assume not... that would fix it such as ^

I have the same problem but I can't install Current Activity Plugin
2018-12-19_13-33-11

I have the same problem but I can't install Current Activity Plugin
2018-12-19_13-33-11

Try to install only in Android Project for test

@DiegoVenancioVieira Try to install only for android project

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivmazurenko picture ivmazurenko  路  3Comments

jimutt picture jimutt  路  8Comments

CesareSoldani picture CesareSoldani  路  6Comments

manonaga2188 picture manonaga2188  路  5Comments

Greg-Freeman picture Greg-Freeman  路  7Comments