How to handle exception when there is no space on the device
I am trying to load a file from a repository firebase
. Where should I handle the exception if there is not enough space on the device?
Below is my code:
if (isExternalStorageWritable()) {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), file.getFileName());
StorageReference ref = ((Jink) (context.getApplicationContext())).getFileStorageRef(file.getFileName());
ref.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// downloaded successfully
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// download fail
}
});
} else {
//could not write to external storage
Toast.makeText(context, context.getString(R.string.resume_download_fail), Toast.LENGTH_SHORT).show();
}
+3
source to share