资产文件夹中的Pdf文件无法在第三方应用中打开 [英] Pdf File In asset folder not open in thirdparty app

查看:86
本文介绍了资产文件夹中的Pdf文件无法在第三方应用中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android新手,我在此路径中存在一些PDF文件 asset/pdf/example.pdf

Hi I am new in android i have some PDF file that exist in this path asset/pdf/example.pdf

当我尝试使用此代码的PDF文件

when i try PDF file with this code

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);

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

i get this error & know it's because third party has no access to file what is solution?

推荐答案

知道这是因为第三方无权访问文件

know it's because third party has no access to file

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

file:///android_asset/ only works for WebView AFAIK.

什么是解决方案?

what is solution?

您可以使用我的 StreamProvider ,其中提供了 ContentProvider ,可以从资产/提供文件.

You can use my StreamProvider, which offers a ContentProvider that can serve a file from assets/.

或者,您可以实现自己的 ContentProvider ,该内容可以从 assets/提供文件.

Or, you can implement your own ContentProvider that can serve the file from assets/.

或者,您可以将资产复制到本地文件(例如,在 getFilesDir() getCacheDir()中),

Or, you can copy the asset to a local file (e.g., in getFilesDir() or getCacheDir()), then use FileProvider to serve that local file.

这篇关于资产文件夹中的Pdf文件无法在第三方应用中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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