如何从资产android的PDF文件? [英] How to get the pdf file from assets in android?

查看:100
本文介绍了如何从资产android的PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我收到来自资产资源,并从中打开PDF文件的文件。
我用这code:

In my application i am getting file from assets resources and open pdf file from it. I am using this code:

Uri path = Uri.parse("file:///android_asset/WindsorONE_Mobile_PK.pdf"); 

            Intent intentPDF = new Intent(Intent.ACTION_VIEW);                     
            intentPDF.setDataAndType(path, "application/pdf");                     
            intentPDF.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                      
            try {                         
                startActivity(intentPDF);                     
            }                      
            catch (ActivityNotFoundException e) {                         
                Toast.makeText(ListSample.this,                              
                     "No Application Available to View PDF",                              
                     Toast.LENGTH_SHORT).show();                     

            }   

可是当我运行code。我得到了错误对话框,文件路径无效
那么,我错了?结果
请帮助E对于这一点。

But While i run that code. I got error Dialog that "File path is not valid" So where i am wrong ?
Please help e for that.

感谢。

推荐答案

的问题是,你传递一个资源路径从应用程序到第三方应用程序,但路径只能从您的应用程序,因为它是内有效私人资源。

The problem is that you're passing a resource path from your application to a third party application, but the path is only valid from within your application since it's for a private resource.

有关这个问题的唯一解决方案是从资产PDF文件复制到外部存储设备,然后给的路径文件(一个在外部存储)的第三方应用程序。那么它应该工作。

The only solution for this is to copy that PDF file from assets to external storage, then give the path to that file (the one in external storage) to the third party app. Then it should work.

这篇关于如何从资产android的PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆