Where to store external csv database so it can be read by App Inventor Android 10, 11

Anke suggested I should merge this topic with the Topic "Please Help Reading File'' so I have repeated the question there and deleted the question below,.which is about how to download EXCEL CSV database files when Android 11 takes over and reading and writing files to external memory will be restricted or not allowed.

Best will be store in Private Storage Directory.

Thanks Sunny,

My problem is how to read csv data from an external source so that I can then write it to an application-specific directory (ASD). A data file such as an EXCEL database in csv format is external it needs to be read and saved as an ASD. It's very similar to a media file in this respect. How can it be read if Android 11 only allows reading from Application Specific Directories? Or have I misunderstood and will Android 11 allow reading external files?

Sorry, I misunderstood about scoped storage of Android 11.
https://developer.android.com/about/versions/11/privacy/storage
Please specify where is that csv data located.

1 Like

Its in the SD drive in a directory called PushTo and in the old days would have been accessed by App Inventor File read or write using /PushTo/Filename.csv. I can read the PushTo csv files using Windows 10 on my PC.or google chrome or using Apps such as File Manager on my phone. The Storage function in Settings tells me that the PushTo directory is on the SD card. File Manager gives me a choice of Root or Internal and shows that the Internal section is where I have the PushTo directory for storing the csv data files.

See here:

1 Like

Thanks for the example Anke. There may be a misunderstanding about my question, which Sunny observed concerns Android 11 scoped storage. I think your example must be working with the legacy version of ReadFile that will stop working when Android 11 takes over. The forward stroke does not work with the non-legacy version see for example the two aia's copied below. Each has the same components but one is the legacy version that can read the external file and the other is the non-legacy version which can only read ASD files.

ReadFileNonLegacy.aia (1.7 KB) ReadFileLegacyMode.aia (1.7 KB)

image
image
My question is how to read an external data file such as an excel database.in the nonLegacy mode? I guess this would be some process similar to reading a media file. I'm also asking if the very useful FileTools functions such as CopyFile, CopyFileAsync, MoveFile, and MoveFileAsync are effectively legacy versions? Will they stop working on external files when Android 11 takes over?

Again thanks for your interest Anke and Sunny and apologies if my question was not clear before. I'd appreciate any advice on how to read databases from the external memory section of the SD card when Android 11 takes over.

1 Like

After looking at the links Anke gave I think to meet the Android 11 requirements it will be necessary to store data files on the web using resources such as Google Drive and then download them using the web component Anke demonstrated in the examples above. I'll try this out and see if something along those lines works - but I don't know if it will continue to be allowed by Google after Android 11 takes over.

Try this (which should work until AI2 targets API 30 (targetSdkVersion=30, probably late 2021):

This should work on all Android versions (also on Android 10, 11).
To check this:

Note:
For this example the text file (Calibration.txt, "12345") is copied from the assets to the folder:

/storage/emulated/0/PushTo/

When AI2 is targeting API 30 you have to save files in the ASD.

1 Like

I tried your APK and it's a very useful example for applying FileTools, EFile and Assets - I will use your examples to upgrade my App file directories to ASD's, and to access data while I learn how to use the App Inventor Web component for when AI2 targets API30. Much appreciated, Peter

Btw, there is also an extension to download files to the external storage - especially to the ASD - without the Web component and without requesting READ / WRITE permissions:

https://community.kodular.io/t/extendeddownloader-extension/71939/34?u=bodymindpower

I would always prefer that because my users - just like myself - are "not amused" about permissions at all. Apart from that, I think it's easier to handle.

PS: However, I'm pretty sure that AI2 will remove these permission requirements (for the ASD from all relevant components: File, Canvas, Web, Player, etc.) when targeting API 30. (True? → @ewpatton).

1 Like

I've upgraded my App so it defaults to internal storage and provides an external storage option for calibration and data files when appropriate. It was straightforward given your examples and the EFile and FileTools extensions. I haven't tried it yet but the ExternalDownloader should make the App readily adaptable to whatever external storage is allowed. Many thanks. Peter

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.