Mediaplugin: App crashing on "TakePhotoAsync" Call

Created on 25 Jan 2018  路  7Comments  路  Source: jamesmontemagno/MediaPlugin

Bug Information

My App is crashing when it calls "TakePhotoAsync" function. I call "CrossMedia.Current.IsCameraAvailable" & "CrossMedia.Current.IsTakePhotoSupported" before it and both returns correct result. "CrossMedia.Current.PickPhotoAsync" works fine in my device.

Version Number of Plugin:3.1.3
Device Tested On: Samsung S6 Edge (Android 7.0-Api24)
Simulator Tested On: Android 4.4 -Api19
Version of VS: 2015
Version of Xamarin: 4.5
Versions of other things you are using:

Steps to reproduce the Behavior

Click on Camera button, it calls (CrossMedia.Current.TakePhotoAsync) and App crashes.

Expected Behavior

Open Camera

Actual Behavior

App crashes

Code snippet

 await CrossMedia.Current.Initialize();


                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( no camera availible.", "Ok");
                    return;
                }

                var file = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(

                    new StoreCameraMediaOptions
                    {
                        Directory = "Images",
                        Name = DateTime.Now + "_test.jpg"

                    });

                if (file == null)
                {
                    return;
                }

                //PathLabel.Text = file.AlbumPath;
                ImageBar.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return stream;
                });

Screenshots

need-more-info

All 7 comments

Could you share the complete crash log/exception stack trace? It will help us to troubleshoot the issue

how try catch?
i have problem it.

I am getting crash on TakePhotoAsync as well. Not sure if it is the same problem as the OP. Here is the crash dump from appcenter:
My calling code is the same as the sample in this project.
Thank you.

MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState)

Java.Lang.RuntimeException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

1 ExceptionDispatchInfo.Throw ()

2 JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)

3 JNIEnv.CallStaticObjectMethod (System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms)

4 FileProvider.GetUriForFile (Android.Content.Context context, System.String authority, Java.IO.File file)

5 MediaPickerActivity.OnCreate (Android.OS.Bundle savedInstanceState)

6 java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

7 android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:584)

8 android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558)

9 android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)

10 md5dff1bed22da39876f271fd39214b8f60.MediaPickerActivity.n_onCreate(Native Method)

11 md5dff1bed22da39876f271fd39214b8f60.MediaPickerActivity.onCreate(MediaPickerActivity.java:42)

12 android.app.Activity.performCreate(Activity.java:6666)

13 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)

14 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)

15 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)

16 android.app.ActivityThread.-wrap12(ActivityThread.java)

17 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)

18 android.os.Handler.dispatchMessage(Handler.java:110)

19 android.os.Looper.loop(Looper.java:203)

20 android.app.ActivityThread.main(ActivityThread.java:6251)

21 java.lang.reflect.Method.invoke(Native Method)

22 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)

23 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

@NoleHealth this is because you didn't setup the file provider: https://github.com/jamesmontemagno/MediaPlugin#android-current-activity-setup

I thought I did but perhaps I have something incorrect. Thanks!

oh! work!
is because you didn't setup the file provider:

@jamesmontemagno I had the provider tag outside of my application tag! Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Julien-Mialon picture Julien-Mialon  路  7Comments

ivmazurenko picture ivmazurenko  路  3Comments

MarcorOnline picture MarcorOnline  路  7Comments

fadaEntrepidus picture fadaEntrepidus  路  6Comments

Glabenwitt picture Glabenwitt  路  4Comments