如何打开先前存储在“privat”文件系统中的文件?该文件是通过webservice下载并应该被存储在本地文件系统中。尝试使用Intent(Action_View)打开文件时出现“奇怪”的错误。虽然文件存在于文件系统中(在模拟器/ Eclipse中的文件浏览器中看到了文件),但它不会显示在启动的相册活动中。相反,相册显示一个黑屏,里面没有任何内容(除了操作栏)。当尝试通过此方法打开pdf /电影/ mp3文件时,情况也是如此(例如,pdf表示文件已损坏)。
顺便说一下:已存储在本地文件系统上的数据是有效的(未损坏),我通过调试器从中下载了文件(通过pull方法),并且可以在我的工作站上打开这些文件...
顺便说一下:已存储在本地文件系统上的数据是有效的(未损坏),我通过调试器从中下载了文件(通过pull方法),并且可以在我的工作站上打开这些文件...
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();
}
}