code: public static boolean isSDCardAvailable() {
          boolean mExternalStorageAvailable = false;
  
          String state = Environment.getExternalStorageState();
  
          if (Environment.MEDIA_MOUNTED.equals(state)) {
              // We can read and write the media
              mExternalStorageAvailable = true;
          } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
              // We can only read the media
              mExternalStorageAvailable = true;
  
          } else {
              // Something else is wrong. It may be one of many other states,
              // but all we need
              // to know is we can neither read nor write
              mExternalStorageAvailable = false;
          }
  
          return mExternalStorageAvailable;
  
      }
docs: Check if the SD Card is Available
  
  @return true if the sd card is available and false if it is not