我正在编写一个应用程序,当您点击按钮时打开PDF文件。以下是我的代码:
File pdfFile = new File(
"android.resource://com.dave.pdfviewer/"
+ R.raw.userguide);
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);
但是当我运行它并按下按钮时,它会说“文档无法打开,因为它不是有效的PDF文档”。这让我很疯狂。我是否正确地访问文件?有什么建议吗?谢谢。