I am trying to save images in a directory inside the application file directory publicly. In public, I mean that I can use the intention of acting on it.
public int SaveBitmap(Bitmap bitmap, String filename, Boolean scan){
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));
bitmap.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
bitmap.recycle();
} catch (IOException e) {
e.printStackTrace();
return 1;
}
File fileR = new File(path);
fileR.setReadable(true, false);
if(scan) ShowInGallery(filename);
return 0;
}
This piece of code does not complete the task; files are still being created in closed mode.
Using:
context.openFileOutput(filename + ".png", Context.MODE_WORLD_READABLE);
I managed to open them publicly, but I can not save the file in a directory.
Please note that I am targeting users who do not have SD cards, so I do not use External Storage.
What can I do?
source
share