Android “内部存储”;文档路径无效";

Android “内部存储”;文档路径无效";,android,Android,错误:文档路径无效 我想将pdf存储在内部存储器中,然后再阅读 我在这个网站上看到了很多que,但没有一个能帮到我 我在Environment.getExternalStorageDirectory()中的代码工作文件现在我将getCacheDir()用于内部存储 用于编写pdf FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray());

错误:文档路径无效

我想将pdf存储在内部存储器中,然后再阅读

我在这个网站上看到了很多que,但没有一个能帮到我

我在Environment.getExternalStorageDirectory()中的代码工作文件现在我将getCacheDir()用于内部存储

用于编写pdf

 FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.close();
file = new File(getCacheDir()+ File.separator+fileName);

PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0 && file.isFile()) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(file);
                intent.setDataAndType(uri, "application/pdf");
                startActivity(intent);
            }
文件写入完成后,我可以在缓存文件夹中看到文件

用于阅读pdf

 FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.close();
file = new File(getCacheDir()+ File.separator+fileName);

PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0 && file.isFile()) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(file);
                intent.setDataAndType(uri, "application/pdf");
                startActivity(intent);
            }
我收到错误“文档路径无效”

使用
getFilesDir()
进行内部存储

公共抽象文件getFilesDir()

在API级别1中添加 返回文件系统上存储使用openFileOutput(String,int)创建的文件的目录的绝对路径

返回 返回保存应用程序文件的目录的路径。 另见 openFileOutput(字符串,int) getFileStreamPath(字符串) getDir(字符串,int)


查看详细信息

您正在尝试将一个应用程序的内部存储(缓存目录)与其他应用程序共享,这在Android中是不允许的。您能解释一下吗?@Nick看到这个讨论,可能会对您有所帮助