I found that on some devices the app gets bugged after taking a photo in landscape mode. My App is designed to be only in the vertical (portrait) mode, this is stated both in the manifest and in the activity definition. When I call MediaStore.CaptureImage intent and the photo is taken in the landscape mode, then upon return to my app, it crashes because my app cannot be rendered in the landscape mode.
As I said this does not happen on every android device, some devices can switch back to the portrait/vertical mode without any problems. Generally, it seems to me this happens mostly on android 11, but it may not be the cause.
In the activity class definition:
ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait
and in the manifest:
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"/>
Intent to call image capture:
Intent intent = new Intent(MediaStore.ActionImageCaptureSecure);
FotkaFile = new Java.IO.File(CestaKFotkam, String.Format(NavstevaPriFoceniRepresentativ + "_{0}.jpg", Guid.NewGuid()));
(new Java.IO.File(CestaKFotkam.ToString())).SetWritable(true, false);
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(FotkaFile));
StartActivityForResult(intent, 0);
After I found out the bug happens only when the photo is taken in the landscape mode, I tried to fix app orientation programmatically upon return from the image capture. Which didn't help.
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
try
{
/*process the photo here*/
}
catch (Exception ex)
{
ShowAlert("Error during image processing:", ex.ToString());
}
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
}
I appreciate any suggestions and comments, Thank you.