简体   繁体   English

Android Open PDF意图

[英]Android Open PDF Intent

I need to open a PDF. 我需要打开一个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. 我正在使用Xamarin,并且该路径存在是因为我检查了一下即可看到。 The app opens Adobe reader, but when it starts an error message shows up saying (File not found). 该应用程序会打开Adobe Reader,但启动时会显示一条错误消息,指出(未找到文件)。 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. 文件夹/data/data/com.myapp是应用程序的专用文件夹。 So no other application can access to the content of this folder (in this case Adobe reader). 因此,没有其他应用程序可以访问此文件夹的内容(在本例中为Adobe Reader)。

Instead try to put your pdf into a SDCard folder. 而是尝试将pdf放入SDCard文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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