如何打开以前存储在“privat”文件系统中的文件?该文件正在通过web服务下载,并应存储在本地fs上。 尝试通过Intent(Action_View)打开文件时出现“奇怪”错误。尽管该文件存在于文件系统中(在emulator/eclipse中的文件浏览器中看到了该文件),但它不会显示在启动的调用Galery活动中。画面中没有内容(除了操作栏)显示黑屏。尝试通过此方法打开pdf/movie/mp3文件时会发生同样的情况(例如,pdf说文件已损坏)。如何通过意图在Android中打开文件
BTW:已存储在本地fs中的数据是有效的(未损坏),我从网上下载的调试器(通过拉法)的文件和文件可以在我的工作站上打开...
public void onAttachment(Context context, Attachment attachment) {
try {
//Attachment is a structured data object that contains of a byte[], filename and mimetype (like image/jpeg)
FileOutputStream fos = FileOutputStream fos = context.openFileOutput(attachment.getAttachmentFileName(), Context.MODE_PRIVATE);
fos.write(attachment.getBinary());
fos.flush();
fos.close();
File f = context.getFileStreamPath(attachment.getAttachmentFileName());
Uri uri = Uri.fromFile(f);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri,attachment.getAttachmentMimetype());
context.startActivity(intent);
} catch (IOException e) {
e.printStackTrace();
}
}
也许http://stackoverflow.com/questions/11068648/launching-an-intent-for-file - 和 - MIME类型/ 11088980#11088980可以帮助。 – ademar111190