如何打开以前存储在"privat“文件系统中的文件?该文件正在由and服务下载,并应存储在本地文件系统中。当我试图通过一个意图(Action_View)打开文件时,我得到了一个“奇怪的”错误。尽管该文件存在于文件系统中(在模拟器/eclipse的文件资源管理器中看到了该文件),但它不会显示在启动的调用galery活动中。galery显示的不是图片,而是一个没有内容的黑色屏幕(除了操作栏)。当试图通过这种方法打开pdf/电影/MP3文件时,也会发生同样的情况(例如,pdf表示该文件已损坏)。
顺便说一句:已经存储在本地文件系统上的数据是有效的(没有损坏),我从调试器下载了文件(通过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();
}
}
https://stackoverflow.com/questions/12585747
复制相似问题