Forum Xamarin.Android

Xamarin Android app crashing with "Intent must include an explicit package name to build an android"

My Xamarin Android app needs to invoke the camera to take a photo and save the URI as well as popping up the gallery so that the user can select an existing photo, again in this scenario I again save the URI of the selected image.

It works say half of the time on my test device which is a cheap Huawei android phone. But about half the time it crashes. Also on other more expensive devices of my test users, it crashes for them often as well.

I am using Azure Mobile Center for crash reporting and I'm seeing this in my error logs:

Intent must include an explicit package name to build an android-app: Intent { dat=content://media/external/images/media/4238 flg=0x1 VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} (has extras) }

In visual studio when I use the Command window -> immed and inspect the intent object, I can see that "Package" is definitely null.

This is the method where I'm creating both types of intent (I.e. for either take photo, or select photo):

    public void HandleRecord(object sender, EventArgs ea)
    {
        String[] items = { "Take Photo", "Choose from Library", "Cancel" };
        ImageUri = null;
        ImageNumber = 0;

        using (var dialogBuilder = new AlertDialog.Builder(this.Activity))
        {
            dialogBuilder.SetTitle("Add Photo");
            dialogBuilder.SetItems(items, (d, args) => {
                //Take photo
                if (args.Which == 0)
                {
                    if (_currentLocation != null)
                    {
                        var intent = new Intent(MediaStore.ActionImageCapture);
                        Java.IO.File _file = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(""), String.Format("NatureMapr_{0}.jpg", Guid.NewGuid()));
                        ImageUri = Android.Net.Uri.FromFile(_file);
                        intent.PutExtra(MediaStore.ExtraOutput, ImageUri);
                        intent.PutExtra(MediaStore.ExtraSizeLimit, "1048576");
                        this.StartActivityForResult(intent, REQUEST_CAMERA);
                    }
                    else
                    {
                        this.Activity.RunOnUiThread(() => Toast.MakeText(this.Activity, "A GPS signal is required!", ToastLength.Short).Show());
                    }
                }
                //Choose from gallery
                else if (args.Which == 1)
                {
                    var intent = new Intent(Intent.ActionPick);
                    intent.SetType("image/*");
                    this.StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), SELECT_FILE);
                }
            });

            dialogBuilder.Show();
        }
    }

An important thing to note is that when the application crashes, it doesn't reach my OnActivityResult method, so something is not happy within the intents that I've created either sometimes and/or some devices.

Many thanks.

Sign In or Register to comment.