任何人都可以帮助我。我想从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..
答案 0 :(得分:0)
您需要将应用程序的res文件夹中的PDF文件写入SD卡。这样其他应用程序就可以阅读并打开它。
因为res文件夹文件仅在您的应用程序本地可用。并且你正在向其他应用程序投掷意图打开那些无法访问它们的pdf。所以删除你的if检查,把你的pfd从res写到sdcard并将该文件传递给意图。