Android 如何从资产文件夹中提供地址?
我打算使用设备的默认应用程序打开PDF文件。我在提供资产文件夹中的地址时遇到问题。Android 如何从资产文件夹中提供地址?,android,assets,Android,Assets,我打算使用设备的默认应用程序打开PDF文件。我在提供资产文件夹中的地址时遇到问题。 我的地址代码如下: File pdfFile = new File("file:///android_assets/test.pdf"); Uri path = Uri.fromFile(pdfFile); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_T
我的地址代码如下:
File pdfFile = new File("file:///android_assets/test.pdf");
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);
当Adobe Reader打开时,此代码给出错误
此路径无效
。正确的地址是什么?它显示错误,因为只有您的应用程序才有权访问该文件夹。您可以考虑将文件复制到另一个目录中(例如SD卡中的某个位置),并向acrobat reader提供复制文件的uri