question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unobserved Task Excpetion of Type "Java.Lang.SecurityException" on Xamarin.Droid when Pick a Photo from Google Fotos App

See original GitHub issue

Bug

On my Lenovo Tablet I get an unobserved Task Exception when I pick an image from the “Google Fotos” App.

Version Number of Plugin: 2.6.0.12-beta Device Tested On: LENOVO Tablet T2-A7-20F

Code:

        pickPhoto.Clicked += async (sender, args) =>
        {
            try
            {
                ChangeButtonEnableState(sender, enable: false);

                await CrossMedia.Current.Initialize();

                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Media Info", "Keine Berechtigung ein Foto auszuwählen.", "OK");
                    return;
                }
                SelectedMedia = new TruckerAppMediaFile
                {
                    Type = MediaType.Photo,
                    File = await CrossMedia.Current.PickPhotoAsync()
                };


                if (SelectedMedia?.File == null)
                {
                    await
                        DisplayAlert("Media Info", "Es wurde kein Foto ausgewählt oder das Foto ist fehlerhaft.",
                            "OK");
                    return;
                }

                var imageStream = await DependencyService.Get<Interfaces.Media.IMedia>()
                    .CopyMediaAsync(SelectedMedia.File.GetStream());
                image.Source = ImageSource.FromStream(() => imageStream);

                SendMedia.IsEnabled = true;
            }
            catch (Exception e)
            {
                await MetricsManagerHelper.SendExceptionToApplicationInsights(e).ConfigureAwait(true);
            }
            finally
            {
                ChangeButtonEnableState(sender, enable: true);
            }

        };

public class AndroidMedia : IMedia
{
    public async Task<Stream> CopyMediaAsync(Stream media)
    {
        // Open the photo and put it in a Stream to return       
        var filestream = new MemoryStream();
        await media.CopyToAsync(filestream);
        filestream.Position = 0;
        return filestream;
    }
}

Expected Behavior

Load / Display my picked image

Actual Behavior

Unobserved Task Exception

Exception Type: Java.Lang.SecurityException

Exception Msg:

Permission Denial: reading com.google.android.apps.photos.contentprovider.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Ffile%2F431/ORIGINAL/NONE/801408323 from pid=6493, uid=10117 requires the provider be exported, or grantUriPermission()

StackTrace:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a8] in /Users/builder/data/lanes/3511/0e59c362/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11687 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00022] in /Users/builder/data/lanes/3511/0e59c362/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:365 at Android.Content.ContentResolver.OpenInputStream (Android.Net.Uri uri) [0x0002c] in /Users/builder/data/lanes/3511/0e59c362/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Content.ContentResolver.cs:884 at Plugin.Media.MediaPickerActivity+<>c__DisplayClass33_0.<GetFileForUriAsync>b__0 () [0x0009d] in C:\projects\mediaplugin\src\Media.Plugin.Android\MediaPickerActivity.cs:534 at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879 at System.Threading.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/3511/f4db8a57/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502

Steps to reproduce the Behavior:

  1. Start my App
  2. Choose “Goolge Fotos” instead of default Gallery
  3. Pick a Foto from
  4. Image is not displayed
  5. Waiting …
  6. Leave the Page
  7. Unobserved Task Exception occured:

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ericbrunnercommented, Oct 29, 2016

Works now on the mentioned Tablet with API LEVEL 19. Thank you for fixing it.

0reactions
ericbrunnercommented, Oct 28, 2016

Thanks. Will try it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java android security exception
I get this error when trying to fire an intent to third-party(it was google photos in my case) gallery app to let choose...
Read more >
Xamarin Android doesn't include exception message in ...
I have a Xamarin Forms Android app on the Google Play store. ... include exception message in JavaProxyThrowable to Google Play Console.
Read more >
Xamarin.Forms: Java.Lang.IllegalStateException
In this instance the code PickPhotoAsync will launch a new intent and Android activity to pick the photo and then return it. This...
Read more >
C#, PHP, C++, iOS, MySQL, SQL, ASP.NET, Objective-C, ...
NET, Xcode, Node.js, string, HTML, Multithreading, image, forms, WinForms, ... google-calendar, instance, data.table, openerp, java.util.scanner, mootools, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found