你好,我是 android 新手,我有一些 PDF 文件存在于该路径中asset/pdf/example.pdf
当我尝试使用此代码创建 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);
我收到此错误并知道这是因为第三方无权访问文件
什么是解决方案?
知道这是因为第三方无法访问文件
file:///android_asset/
只适用于WebView
AFAIK.
什么是解决方案?
您可以使用my StreamProvider https://github.com/commonsguy/cwac-provider,它提供了一个ContentProvider
可以从以下位置提供文件assets/
.
或者,您可以实现自己的ContentProvider
可以从以下位置提供文件assets/
.
或者,您可以将资源复制到本地文件(例如,在getFilesDir()
or getCacheDir()
), 然后使用FileProvider提供该本地文件 https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/V4FileProvider.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)