0
votes

I'm working on Xamarin Android project and I want to implement taking photo with MvvmCross.

Here's my code:

public class PhotoService:IPhotoService
{
    private const int MaxPixelDimension = 1280;
    private const int DefaultJpegQuality = 90;

    private Stream imageStream;

    public Stream ImageStream
    {
        get { return imageStream; }
        set { imageStream = value; }
    }

    public void GetPhoto()
    {
        var task = Mvx.Resolve<IMvxPictureChooserTask>();

        task.TakePicture(
        MaxPixelDimension,
        DefaultJpegQuality,
        SavePicture, null);
    }

    private void SavePicture(Stream stream)
    {
        ImageStream = stream;
    }

}

but in:

task.TakePicture(
        MaxPixelDimension,
        DefaultJpegQuality,
        SavePicture,
        null);

I have error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

UPDATE

in call stack I have:

0x0 in Android.Content.Intent..ctor at /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Content.Intent.cs:1275,6 C# 0x12 in MvvmCross.Plugins.PictureChooser.Droid.MvxPictureChooserTask.TakePicture C#
0x3A in App.Services.PhotoService.PhotoService.GetPhoto at C:\app\App.Services\PhotoService\PhotoService.cs:38,4 C#
0x7 in App.ViewModels.ViewModels.MainViewModel.TakePhoto at C:\app\App.ViewModels\ViewModels\MainViewModel.cs:49,4 C#

2
Do you have more information? Such as a stack trace. Maybe inner exceptions? - Cheesebaron
@Cheesebaron Question updated - Quiet
That doesn't seem like the entire stack trace. - Cheesebaron
@Cheesebaron how to get it? - Quiet

2 Answers

1
votes

Alternative solution you can use Media Plugin that available in nuget

https://www.nuget.org/packages/Xam.Plugin.Media/

You can use dependency service to call the takePictureAsync method from android project. With this library you can specify file name and folder path to store your image. This library can also take video using takeVideoAsync method.

0
votes

I believe you need to add the MVVMCross.Pugin.PictureChooser package to your Core and platform specific projects.