Thanks for your comment and I appreciate you trying to save me time by sending the APK but I'm afraid I don't download APKs unless they are from Google Play. I implemented the app by hand from your blocks diagram to ensure I hadn't missed anything and with the file options in Designer set to Shared scope and with the read and write permissions ticked. The app didn't work on Android 11. On pressing the 'Save' button it produced an error 908 "The Permission Write_ExternalStorage has been denied". I believe this is because the leading forward stroke on your file path invokes the Android 10 Legacy option.
"Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single / will be read from and written to the root of the external storage directory, e.g., /sdcard/. Legacy functionality will not work on Android 11 or later."
"Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag."
The original question remains open. The AI2 File component is unable to read or write shared text files in the Download and Document media folders with the current version of Android 11. Is this a bug or is it intended?".
I set the scope to Shared in the screen and ticked the read and write permissions, as my question is whether the AI2 Files component when set to Shared Storage scope is working as intended or has a bug. When set to Legacy there is no problem other than the fact that Android 11 no longer recognises the Legacy option.
In the past, I've used your and others' file extensions and they have worked very effectively. Now I'm trying to prepare the app for distribution and want to ensure it will work on Android 11 and can be distributed by Google Play.
I think that is only true if you intend to sometimes use versions of Android released before Android 11 and I see no requirement to do this in the MIT Storage definition:
I can see it would be useful to set the default to Legacy in an App that is intended for many versions of Android. But it would compromise the validity of any test of Files for use in Android 11. I have taken great pains to avoid this kind of compromise in my tests. I should also mention that for these tests I always set the File component scope to Shared as well as the screen scope property.
I have tested my test app and Johannes test app with the screen storage scope set to Legacy and the file component property to Shared. There is no change in the response for either. They both show "Error 908: The permission Write_External_Storage has been denied. Please enable it in the Settings app". These permissions don't exist in the Android 11 Settings App and the alternative Files/Media permission has already been set for these apps in the phone I am using.
Both storage permissions are required on all Android versions. Unfortunately incorrectly even on Android 11+ (meaning it should work on Android 11+ without any storage permissions).
In order for both permissions to be declared in the Manifest on all Android version (even on Android 11+), → DefaultFileScopemust be set to → Legacy in the designer.
Note: WRITE permission is no longer avialable on Android 11, but is still wrongly needed to make it work on Android 11+ devices.
Check this app (especially on your Android 11+ devices). Download the aia, build the APK and install it: textFile_save.aia (2.7 KB)
Explanation: If this file "myTextFile.txt" has already been created by another app, it cannot be overwritten (on Android 11+). Therefore the file name has to be changed.
Thank you all. Taifun correctly identified that I was confused by the need for two apparently conflicting assignments of the Default File Scope and the read and write permissions and that the screen Default File Scope would have to be set to Legacy. I also didn't realise that this was the essential modification in Anke's app which resolves part of the question raised in this thread.
Hi Anke, Thank you for the App and the very clear explanation. I had acknowledged your identification of this problem earlier in this thread but didn't understand it correctly until I saw your explanation just now. I also mentioned earlier that the AI2 Shared File Scope allows an app to read, write and export files that it generates, but does not allow an external text media file to be read from the Download or Documents folders and generates the "Error 2102: The File Download/Filename.txt could not be opened". This is not corrected by setting the Screen Default File Scope to Legacy. My question is whether this is intended behaviour or a bug?
To access (read / write) non-media files, that are not created by the app itself, you must use the Storage Access Framework (SAF). See also here from my overview → Some basic on Android storage: