我试图将图像保存在app文件目录中的公共目录中.通过公开,我的意思是我将能够使用动作视图意图.
/** 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卡的用户,这就是我不使用外部存储的原因.
我能做什么?