繁体   English   中英

如何从android studio中的res文件夹中读取pdf文件

[英]how to read pdf files from res folder in a android studio

谁能帮我。 我想从app / src / main / res / Unit1.pdf中读取pdf文件,我的代码是

File file1=new File("app/src/main/res/Unit1.pdf")
Uri path1=Uri.fromFile(file1);
if (file1.exists())
{
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path1, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e){
Toast.makeText(MainActivity.this,"No Application Availabel To View
PDF",Toast.LENGTH_SHORT).show();
}
}

if section not working....plz help..

您需要将应用程序res文件夹中存在的PDF文件写入sdcard。 以便其他应用程序可以读取并打开它。

如在res文件夹文件仅在本地可用于您的应用程序。 并且您正打算让其他应用打开无法访问的pdf。 因此删除您的if检查,将pfd从res写入sdcard并将该文件的uri传递给意图。

暂无
暂无

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

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