Android 如何打开存储在GetFileDir().getPath()路径中的PDF文件
我已在路径Android 如何打开存储在GetFileDir().getPath()路径中的PDF文件,android,Android,我已在路径getFilesDir().getPath()中将PDF文件下载到我的应用程序中 当我尝试使用以下代码打开同一文件时: String path = getBaseContext().getFilesDir().getPath()+"/myfile.pdf"; File file = new File(path); Intent intent = new Intent(Intent.ACTION_VIEW); intent.
getFilesDir().getPath()中将PDF文件下载到我的应用程序中
当我尝试使用以下代码打开同一文件时:
String path = getBaseContext().getFilesDir().getPath()+"/myfile.pdf";
File file = new File(path);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
我从pdf阅读器中得到目标文件不存在的错误
当我在设备上浏览myfile.pdf
路径时,它位于“/sdcard/Android/data/com.*.*.*.*.*/files/data/com.*.*.*.*.*/files/myfile.pdf”
。
如果我硬编码上面的路径,那么我也会得到同样的错误
请告诉我如何从该路径读取文件。使用:Environment.getExternalStorageDirectory().getAbsolutePath()
感谢您的帮助,但是Environment.getExternalStorageDirectory().getAbsolutePath()在我的情况下不起作用。
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfile.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);