Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Xamarin.Forms Android App Restarts after Camera taking photo

$
0
0

I have a Xamarin. Forms application, and when the application starts everything working fine. After that, I want to take and store the photo using our phone's camera. Here the problem is when I was the open camera and taking the photo, After I click the save button it is not returning OnActivityResult Method. The camera that will be crashing the MainActivity.cs, Then XF is restarted and the app starts on the MainPage.

Xamarin.Forms Android - v3.5.0.274416

MainActivity.cs Code :-

      BtnCamera.ShouldTakePicture += () =>
                    {
                       var intent = new Intent(MediaStore.ActionImageCapture);
                        var filePath = CreateFilePath.GetFilePath();
                        Java.IO.File file;

                            file = new Java.IO.File(filePath, TruckDetails.TripID +  Guid.NewGuid().ToString() +".png");

                        (new Java.IO.File(filePath)).SetWritable(true, false);
                        intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
                         StartActivityForResult(intent, 100);
            };

PS :-
1. I am not used MediaPlugin DLL.
2. It is not happening every time.

App Center Log -:

    Android: 9
    Android Build: PPOS29.114-134-7-7
    Manufacturer: motorola
    Model: moto g(7) power
    CrashReporter Key: 1e8720f8-b0fb-42b5-bf1c-d6466eb00140
    Start Date: 2020-06-29T03:01:10.721Z
    Date: 2020-06-29T03:01:12.758Z

    Xamarin Exception Stack:
    System.NullReferenceException: Object reference not set to an instance of an object
      at Scoular.Droid.MainActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00240] in <4dd616694d1a48ffb7992593dad90b4a>:0
      at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <ff07eae8184a40a08e79049bbcb31a0e>:0
      at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <b62c3fba3fe848f3bb323dbe33464223>:0
      at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.29(intptr,intptr

Thanks advance :)


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>