How to handle exception when there is no space on device

Viewed 259

I am trying to download file from firebase storage. Where should I handle exception if there is not enough space on 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();
    }
1 Answers
Related