Reputation: 2004
Xamarin Forms Android crashes while taking photo without exception. But this happens in like 65% of tries. Sometimes app doesn't crash and I can take photo normally. On other phone(same model) application crashes every time I want to take photo.
I'm using https://github.com/jamesmontemagno/MediaPlugin like this:
if (!CrossMedia.Current.IsCameraAvailable)
{
DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "testPO.jpg"
});
if (file == null)
return;
DisplayAlert("File Location", file.Path, "OK");
Camera loads without problem, but when I press "Take photo" button application crashes and debugging in Visual Studio stops without any exception.
Thank you for any help.
Upvotes: 3
Views: 2216
Reputation: 172
I realize this is old but in case someone stumbles across this issue in the future:
I've had this issue and it ended up being the NoHistory
flag in MainActivity.cs
being set to true
.
Remove NoHistory = true
or set NoHistory = false
to avoid the crash.
eg:
[Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, NoHistory = false)]
public class MainActivity : FormsAppCompatActivity {
//...
}
Upvotes: 2