Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何打开存储在GetFileDir().getPath()路径中的PDF文件_Android - Fatal编程技术网

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);