I'm saving a Bitmap in order to send the file name to another activity. This is the code I'm using to do this:
@Nullable
public static String saveImage(Context context, Bitmap bitmap, int pos, String TAG)
{
String fileName = "thumbnail_" + pos + ".png";
try
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
FileOutputStream fileOutStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
fileOutStream.write(byteArray);
fileOutStream.close();
} catch (IOException ioe) {
ioe.printStackTrace();
Log.e(TAG, "Error guardando la imagen");
return null;
}
return fileName;
}
What I want to do is when exiting the activity, delete this image. How can I know where this image has been saved and how can I delete it?
Thanks in advance,
fileName
is the path to your file in your app internal storage and your Context
has a method called deleteFile(String name)
where name
is your fileName
.
So, just call context.deleteFile(fileName)
.
You can check the documentation here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.