我试图将应用程序文件目录中的图像公开存储在目录中。通过公开,我的意思是我可以使用动作视图意图。android:公开存放目录中的内部存储文件
/** Saves the bitmap to app storage */
public int SaveBitmap(Bitmap bitmap, String filename, Boolean scan){
// Save the file
OutputStream os = null;
String path = context.getFilesDir() + "/MyAppName/";
File file = new File(path);
if(!file.isDirectory())file.mkdirs();
path += (filename + ".png");
try {
os = new BufferedOutputStream(new FileOutputStream(path,true));
//os = mContext.openFileOutput(, Context.MODE_PRIVATE);
bitmap.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
bitmap.recycle();
} catch (IOException e) {
e.printStackTrace();
return 1; //Failure
}
File fileR = new File(path);
fileR.setReadable(true, false);
// Show in Gallery
if(scan) ShowInGallery(filename);
return 0; // SUCCESS
}
这段代码不会做的工作,这些文件私下模式仍在产生。
使用:
context.openFileOutput(filename + ".png", Context.MODE_WORLD_READABLE);
我能够公开打开它们,但我不能将文件保存在一个目录。
请注意,我针对的用户没有SD卡,这就是为什么我没有使用外部存储。
我该怎么办?
如果重要的是图像保持“私人”,除非采取行动,那么您将需要实施一个“ContentProvider”来让其他应用程序或意图临时访问您的数据。如果所有图像都可以访问,您可以简单地将它们存储在外部,如下面解释的答案。 – 323go
阅读文档'context.getFilesDir' – njzk2
@ njzk2 - 没有帮助,那是内部存储。 – katzenhut