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

If I remove all files from /Download and /Documents and the unistall and reinstall the app, I get this:

and the text file are not saved in /Documents (but only in /Download).

Note: In /Documents is only saved again when the number of previously created text files is exceeded (i.e. the app remembers how many files have been saved, even after they have been deleted).

But it’s working fine for me even after uninstalling and reinstalling (after deleting those files)

Ok thanks, I’ll test it later on one of my Android 10 devices.
Maybe it’s working there.

1 Like

Yes, it works on Android 10, but NOT on Android 11.

1 Like

Okay, I have no Android 11 Device,
But if scoped storage is there for Android 11 then what’s the issue?

Maybe it has to do with:
On Android 10 permission asks to grant access to

  • photos,
  • media files and
  • files.

But on Android 11 it is only asked to grant access for

  • photos and
  • media files.
1 Like

I would like to understand this behavior, specifically how it is possible to save in /Download or /Documents without WRITE permission (and without using shared storage).

But of course you are right that this is (no longer) necessary if scoped (shared) storage is implemented correctly (in AI2).

Maybe if the path is available to be used as scoped storage, you can write the files there without any issue.

1 Like

Yes maybe, but only media files are mentioned there.
But what about non-media files (.txt, pdf, …).

Would you mind sharing your bugfix with the MIT App Inventor Team?

Taifun
PS: keep up the good work…

4 Likes

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

Here is a text APK that copies a text file or image from the assets to the shared storage (and reads the text from the text file or shows the image). This works for the text file (as it should be without READ / WRITE permissions). The image is copied (of course without WRITE permission, which is no longer available on Android 11), but the image is ONLY displayed if READ permission has been granted beforehand. Note: This should (in my opinion) be possible without READ permission.

FileTestSharedStorage_Nio.apk (5.2 MB)
I tested the APK on a Pixel 2XL (Android 11).

Btw, the same problem with AI2, (but there are also some other issues).

1 Like

Noted the issue, it should be fixed soon.

3 Likes