Can't write file to SHARED directories on API31 (Android 12)

Hi,
Could anybody suggest any working on API31 combination of path, context of file component and default context of application (on Screen1) to write and read file in shared folders (Documents or Download) please?
I use file component to File1.SaveFile.

And Yes, I have searched this forum, tried multiple combinations of App/Shared context of both Screen1 and File component as well as short/full path styles for the path (/Download/, /storage/emulated/0/Download/ and file:///storage/emulated/0/Download/) . I do not want you to analyse my blocks - either anybody has tried and knows combination of these 3 parameters (Application default context, file component context, path) or not

See also here:

1 Like

Thanks a lot for help and MFile component.
This allows me to restore writing to Shared folders on API29-API31.

I did not understand point on necessity to delete files + I can't make MFile delete /Download/MyTempFolder (File component did have recursive flag allowing me to clean-up...) but these are not really my top priorities for a while :wink:

Thanks again !

Because your app is not able to overwrite files from other apps

Taifun

1 Like

Thanks for all the explanations. I've done some tests on API30 and API31:

  1. Deleting non-empty directories requires knowing the content (->Delete for each file in TaifunFile.FileList),
  2. On devices shared by 2 people (Settings->Users and ...->Users), root folder may not be /storage/emulated/0/ - replace zero by what u find in e.g. MFile.ApplicationSpecificDirPath
    Best regards

:question:

:question:

I don't understand both points, but I should if they were worded in an understandable way.

what you are trying to say is, you tested on an Android 11 and Android 12 device
the target sdk for App Inventor apps is always SDK30...

yes, this is how my file extension works... if there are files inside a directory you first have to delete the files before you are able to delete the directory

Taifun

Yes, and this is the same with the File component.
But the FileTools extension can also delete a non-empty folder.

Knowing the content is irrelevant, it just has to be files (content) that the app created itself.

I new in Android so so things obvious to You are not to me ... :slight_smile: Part of my problem was that Download folder was not in " /storage/emulated/0/Download" but in "/storage/emulated/10/Download" instead. I did not find a function "getSharedFoldersRoot" giving "/storage/emulated/0/" or /storage/emulated/10/ or whatever is appropriate on given device (so I've put together some blocks :wink: ). Thanks for all the support.

Something like this:

Thanks. Unfortunatelly I've deleted my question .... so here I re-crete it:
...
MFileLoop

One more : what is proper way to append rows sequentially in the loop ? Scenario is simple: I have a header string ending \n (generated by _AdifHeader function) and a list (log). I create file writing Header MFile.Save and I iterate list using _AdifRow function that renders string ended by "\n" (lines) and write these using MFile.Append. It looks to me that subsequent Appends neither wait for file operations before them nor make sure thay are written sequentially. Sometimes they are out of order, sometimes (as now) first appended line looks live overriden by preceding SaveFile operation. I've found it only now ... I'll try to reproduce it with File component... Help me please.
...
Anyway:

  1. is it safe in AppInventor to call from within AfterFileSave another save ?
  2. it requires use of global variables (counter and buffer) and accessing it implicitly - I want to avoid it as much as possible in my code as it makes any change/debuging extremely difficult and code gets error-prone
  3. What is safe lenght of Text (so that I create veeeeeeery long text having all lines and write it at once) ?

Yes. This ensures that each item in your list is appended to the file and saved before the next item.

Don't see this as an issue. You won't be accessing the file whilst you add items from your list ? Using a counter means it has to be a global variable. Not sure what you mean by buffer ?

Length of lines in a text file, size of a text file, and size of data stored in a tinydb are generally limited by the storage memory capacity of the device. Others have stored entire books/novels in a single file, and displayed then in a single label.

Thanks for all the explanations, patience and great help.