In a class which is not Activity and thus doesn't have a Context I need to store a file like:
public static void saveAvatar(String fileName, Bitmap avatar) {
if (avatar == null)
return;
FileOutputStream fos;
try {
fos = context.openFileOutput(fileName + ".jpg", Context.MODE_PRIVATE);
avatar.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
To make it work I need to keep a context in a class because I'm calling this method from another class which doesn't have a context either. Is there a way to do it without context like using ContentResolver or something like?