Aia with 500 (text) files in the assets / File.Exists_scope

Apparently, it seems that ewan already commited a fix that solves the crashing issue from method ‘openForWriting’ : appinventor-sources/FileUtil.java at hotfix/legacy-files2 · ewpatton/appinventor-sources · GitHub
But still one change is missing if they want to support most available paths like ‘Documents’,
instead of returning ‘null’ in method getContentUriForPath, this code should be added :

 else {
      return MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL);
    }

Full Method Code :

  private static Uri getContentUriForPath(String path) {
    if ("DCIM".equals(path) || "Pictures".equals(path) || "Screenshots".equals(path)) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        return MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
      }
      return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    } else if ("Videos".equals(path) || "Movies".equals(path)) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        return MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
      }
      return MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    } else if ("Audio".equals(path) || "Music".equals(path)) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        return MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
      }
      return MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
        && ("Download".equals(path) || "Downloads".equals(path))) {
      return MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL);
    } else {
      return MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL);
    }
  }
3 Likes