【发布时间】:2013-10-21 07:25:11
【问题描述】:
错误:文档路径无效
我想将 pdf 存储在内部存储中并在我想阅读它之后。
我在这个网站上看到了很多问题,但没有一个能帮助我。
我在 Environment.getExternalStorageDirectory() 中的代码工作文件现在我使用 getCacheDir() 进行内部存储。
用于编写 pdf
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
文件写入完成,可以看到缓存文件夹中的文件了。
用于阅读 pdf
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);
}
我收到错误“文档路径无效”
【问题讨论】:
-
您正在尝试将一个应用程序的内部存储(缓存目录)与其他应用程序共享,这在 Android 中是不允许的。
标签: android