2016-09-17 57 views
-1

您好我是新的android系统中我有一个存在于这个路径的一些PDF文件无法打开asset/pdf/example.pdfPDF文件在资产文件夹中的第三方应用程序

当我尝试PDF文件与此代码

Intent intent = new Intent(Intent.ACTION_VIEW); 
    File file = new File("file:///android_asset/pdf/example.pdf"); 
    intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
    startActivity(intent); 

我得到这个错误&知道这是因为第三方无法访问文件 什么是解决方案?

回答

0

知道这是因为第三方有没有访问文件

file:///android_asset/仅适用于WebView AFAIK。

什么是解决方案?

您可以使用my StreamProvider,它提供了一个ContentProvider可以从assets/服务的文件。

或者,您可以实施自己的ContentProvider,该服务可以从assets/提供该文件。或者,您可以将资产复制到本地文件(例如,getFilesDir()getCacheDir()),then use FileProvider to serve that local file

+0

老兄在提问之前我也读过你的GITHUB项目,但不能再处理它!我新,不知道如何使用流提供程序你可以写在我的文件路径基础,并给我例子? –

+0

@MohamadAmin:[StreamProvider'' demo /'project](https://github.com/commonsguy/cwac-provider/tree/master/demo)演示了如何从资产中提供文件等等。因此,我的许多书籍的拖放式样本,例如[this one](https://github.com/commonsguy/cw-omnibus/tree/master/DragDrop/Legacy)(StreamProvider)用于'drag /'app模块)。 – CommonsWare

+0

我无法处理:(尝试两个小时 –

相关问题