MediaPlugin: TakePhotoAsync causes crash from unmanaged code, can't catch, app crashes
Bug Information
Version Number of Plugin: Xam.Plugin.Media 5.0.1 Device Tested On: iPad 7th Generation, iOS 14.4.2 Simulator Tested On: N/A Version of VS: VS Mac 8.9.4 (build 25) Version of Xamarin: 5.0.0.2012 Versions of other things you are using:
Steps to reproduce the Behavior
Verify camera permissions, bring up camera via await CrossMedia.Current.TakePhotoAsync, take a picture and click “Use Photo”. App crashes, but not always.
Expected Behavior
Call await CrossMedia.Current.TakePhotoAsync and get back media file or null.
Actual Behavior
App crashes due to an exception in unmanaged code.
Code snippet
var status = await Permissions.CheckStatusAsync<Permissions.Camera>();
if (status != PermissionStatus.Granted || !CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { /* Abort. */ }
var options = new StoreCameraMediaOptions
{
Directory = "Test",
SaveToAlbum = false,
CompressionQuality = 75,
CustomPhotoSize = 50,
PhotoSize = PhotoSize.MaxWidthHeight,
MaxWidthHeight = 2000,
DefaultCamera = CameraDevice.Rear,
SaveMetaData = true,
AllowCropping = false
};
MediaFile file = null;
try { file = await CrossMedia.Current.TakePhotoAsync(options); }
catch (Exception ex) { file = null; }
Screenshots
See stack trace https://gist.github.com/daveblt/08a6991b8aa5ea606daf2444d52bb099
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (1 by maintainers)
We’ve had this issue for the last 6 months. Last week we found this tutorial . After we set up Plugin.CurrentActivity plugin for Media Plugin to attach itself to the active Activity during the run time. And like magic, no more crashes. We believe that since it is attached to the activity, android does not mess with it.
Hope it helps fix the issue for other people.
Just sharing my experience, it might help someone…
I have recently migrated from CrossMedia to MediaPicker and I have been trough much more trouble than I expected…
First of all, just to install the Xamarin.Essentials library, I had to migrate to androidX and d8 dex compiler in order to build the app again.
after that, when I put everything to work again. I had to do some image processing (resizing and rotating the pictures taken) to do, so that everything worked smoothly. Otherwise, the picture taken would be sideways and too large.
I am currently testing with some users to see if the white screen intermitent error stops for good. Once I get the results, I’ll come here share with you!
cheers
I am experiencing the same problem on Android 11! Does someone figured a workaround?
Cheers!