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

如何在android studio中从res文件夹读取pdf文件,android,Android,有人能帮我吗。我想从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.s

有人能帮我吗。我想从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文件写入SD卡。以便其他应用程序可以读取并打开它


在res中,文件夹文件仅对应用程序本地可用。你正在试图让其他应用程序打开他们无法访问的pdf。因此,删除if检查,将pfd从res写入sdcard,并将该文件的uri传递给intent。

文件打开在Android上的工作方式不同,请先检查它的工作方式。