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


1 answer


Presumably the write to disk will fail, which means we'll write this and route it through OnFailureListener

with a shared ERROR_UNKNOWN

(per docs ) file system error embedded in the error message.



+1


source







All Articles