0

My Xamarin app allows the user to take a new, or select an existing image.

It works perfectly fine on almost all devices, but I'm getting error reports from Samsung Galaxy S7 users and it appears that the intent data is null after those users select an existing image from their gallery.

Here's how I setup the intent:

var intent = new Intent();
intent = new Intent(Intent.ActionGetContent);
intent.SetType("image/*");

try
{
    Xamarin.Forms.Forms.Context.PackageManager.GetPackageInfo("com.android.gallery", 0);
    intent.SetPackage("com.android.gallery");
}
catch { }

this.StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), SELECT_FILE);

And here's how I grab the Uri in OnActivityResult after image selection:

public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
    ContentResolver resolver = this.Activity.ContentResolver;

    if (resultCode == Result.Ok && requestCode == SELECT_FILE)
    {
        ImageUri = data.Data;
    }
}

So I'm going nuts trying to work out why data.Data is null only on a select few devices, namely Samsung Galaxy S7.

Aaron
  • 1,802
  • 3
  • 23
  • 50
  • I do not have the code in front of me, but to not *force* the usage of the `com.android.gallery` package (this will fail in many different ways on different vendor API flavors, Samsung implements a lot of ASOP features in their style, especially their camera/gallery integrations), use an action pick and use the MediaStore to determine the which packages on the device support selecting external content... – SushiHangover Apr 01 '17 at 02:29
  • Thanks. The reason I had hard baked the com.android.gallery in was to resolve another error on some devices where the code crashed telling me that I needed to explicitly specify a package. But maybe hardbaking it to com.android.gallery is not the right approach. Do you know how I can get the list of packages which support image selection? Maybe I should do that and then just select the first package that is returned? – Aaron Apr 01 '17 at 02:38
  • Try checking this answer: http://stackoverflow.com/a/28456228/883738 or this http://stackoverflow.com/a/28455794/883738 – Alex Sorokoletov Apr 01 '17 at 17:23

0 Answers0