0

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#

4
  • Do you have more information? Such as a stack trace. Maybe inner exceptions? Commented Feb 13, 2017 at 20:15
  • @Cheesebaron Question updated Commented Feb 13, 2017 at 21:20
  • That doesn't seem like the entire stack trace. Commented Feb 13, 2017 at 22:08
  • @Cheesebaron how to get it? Commented Feb 13, 2017 at 22:17

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

I have only android project. I added this plugin to Android (core) and my android class library where is PhotoService

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.