Unobserved Task Excpetion of Type "Java.Lang.SecurityException" on Xamarin.Droid when Pick a Photo from Google Fotos App
See original GitHub issueBug
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:
- Start my App
- Choose “Goolge Fotos” instead of default Gallery
- Pick a Foto from
- Image is not displayed
- Waiting …
- Leave the Page
- Unobserved Task Exception occured:
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Works now on the mentioned Tablet with API LEVEL 19. Thank you for fixing it.
Thanks. Will try it.