CrossMedia.Current.IsCameraAvailable = System.NotImplementedException:

Hi friends,
I have created a simple xmal page in PCL project which use to Take Photo and Pick Picture from gallery. The problem is when I click any of the option, its trigger respective method but nothing can be seen after that. Internally, its fired the below error.

CrossMedia.Current.IsCameraAvailable = System.NotImplementedException: This functionality is not implemented in the portable version of this assembly.
You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

Kindly let me know what is missing here...

Package:

















Xaml code:

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage.Content>

<StackLayout BackgroundColor="#123440">

  <Image
      HeightRequest="24"
      WidthRequest="24"
      HorizontalOptions="Center"
      Source="camera_p.png">

    <Image.GestureRecognizers>
      <TapGestureRecognizer
              Tapped="OnTapCamera"
              NumberOfTapsRequired="1" />
    </Image.GestureRecognizers>
  </Image>

  <Image
      HeightRequest="24"
      WidthRequest="24"
      HorizontalOptions="Center"
      Source="pick_p.png">

    <Image.GestureRecognizers>
      <TapGestureRecognizer
              Tapped="OnTapGallery"
              NumberOfTapsRequired="1" />
    </Image.GestureRecognizers>
  </Image>

</StackLayout>

</ContentPage.Content>

cs code:

private void OnTapCamera(object sender, EventArgs args)
{
//var imageSender = (Image)sender;
TakePhoto();
}

    private void OnTapGallery(object sender, EventArgs args)
    {
        //var imageSender = (Image)sender;
        PickPhoto();
    }

    public async Task TakePhoto()
    {
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await DisplayAlert("Alert", ":( No camera available.", "OK");
            return;
        }

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

        if (file == null)
            return;

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

    }

    public async Task PickPhoto()
    {
        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await DisplayAlert("Alert", ":( Permission not granted to photos.", "OK");
            return;
        }
        var file = await CrossMedia.Current.PickPhotoAsync();


        if (file == null)
            return;

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

Posts

  • AdnanKhanAdnanKhan USMember ✭✭
    edited December 2016

    Did you find solution for this. I am getting same error message. I am using PCL Profile #7.
    Thanks

  • AdnanKhanAdnanKhan USMember ✭✭

    I got it working I had to install the same plugin package on Android and IOS project.

Sign In or Register to comment.