View a PDF with Device.OpenUri

Hi folks,

Looking for some pointers please as I've trawled the internet but can't find a consistent, working, up to date explanation/example how to open a PDF in the Android portion of a cross-platform, .NET standard project? I'm using the code below to return a list of files in a directory...

        private void Listy_ItemSelected(object sender, SelectedItemChangedEventArgs e)
                var getSelected = e.SelectedItem as IFile;
                var getPath = getSelected.Path.ToString();
                string myUri = (getPath);  _// getPath = "sdcard/download/PDFiWant2Open.pdf"  _
                Device.OpenUri(new Uri("content:///" + myUri));

If I use Device.OpenUri(new Uri("content:///" + myUri)); I get Unhandled Exception: Java.Lang.SecurityException
If I use Device.OpenUri(new Uri("file:///" + myUri)); I get Unhandled Exception: Android.OS.FileUriExposedException

I'm stuck trying to resolve either! Am I just going about this completely the wrong way? Need additional code/settings/etc? let me know, any suggestions, pointers/links or examples would be most welcome...


Sign In or Register to comment.