简体   繁体   中英

Android Open PDF Intent

I need to open a PDF. I know the procedure, this is my code:

string file_path = _path + url.Substring (5);
                if (System.IO.File.Exists(file_path)) {
                    Android.Net.Uri pdfFile = Android.Net.Uri.FromFile (new Java.IO.File (file_path));
                    Intent pdfIntent = new Intent (Intent.ActionView);
                    pdfIntent.SetDataAndType (pdfFile, "application/pdf");
                    pdfIntent.SetFlags (ActivityFlags.NoHistory);
                    _parent.StartActivity (pdfIntent);

                    return true;
                }

I'm using Xamarin, and the path exists because i check it as you can see. The app opens Adobe reader, but when it starts an error message shows up saying (File not found). So, my file is in

/data/data/com.myapp/files/.hide/contents/file_test.pdf

Are there some permission to set? I really don't understand why it can't open my file!

The folder /data/data/com.myapp is the private folder of your application. So no other application can access to the content of this folder (in this case Adobe reader).

Instead try to put your pdf into a SDCard folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM