如何打開以前存儲在「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