Options to read CSV external file into App

I have gone thru How to access non-media files on Android 11, Basics on Android storage, and the SAF Extension and I'm drawing a blank.

Here's my case: I have a CSV file created outside the App (w/ MSoft Excel) with the 10k most common words (to be used in a predictive text function of text input). The file is a 10k row by 14 column table with the 1,2,3...8 character fragments of each word and other word-specific data (very easy to create and manipulate in Excel). This CSV (i.e. Excel) file may receive updates down the road.

It is read only once (at Screen1.initialize) then a TinyDB is created (or updated if there are new words in the CSV file) and then it is loaded into a list where it is used by the rest of the App functions. New words added locally by the user are stored in the TinyDB and remain only there. The CSV file is read-only.

When connecting my Android 11 tablet via USB to my laptop, the main folder appears as an external drive called "Internal Shared Storage", with subfolders including /Download, all types of media and /Android/data/nameOfMyApp.

I can copy the CSV file into any of these folders and the App running in AI Companion can read it and everything works just fine, but, the compiled .apk comes back with "Error 2102: file can't be opened" regardless of where I place the CSV file.

  1. I'm guessing the AI Companion has MANAGE_EXTERNAL_STORAGE permission?

  2. If the folder is called "Internal Shared Storage", is it Internal or is it shared?

  3. From the forum's Android Storage Basics

I can extrapolate that in my tablet, the path of the ASD is:
Internal shared storage/Android/data/nameOfMyApp/files/
but, placing the CSV file there still generates Error 2102 in the compiled app.

  1. Given this use case (read CSV file only once from an outside source), do you recommend to go SAF Extension, Web download, request `MANAGE_EXTERNAL_STORAGE, or some other option (all entail a learning curve so I'm trying to pick ONE).

Thanks!!

Once file downloaded to your ASD, you should have no issue with reading the file with the File component, and then setting it to tinydb.

(You can of course just use the web component to download the file, but you may be asked to give permission)

1 Like

No

Follow @TIMAI2's advice or store the file in shared storage /Download and access it using SAF

Taifun

1 Like

If you do not plan to publish the app, then this would be an easy way to do it

Taifun

1 Like

@Taifun @TIMAI2 @Anke

I am in complete AWE at the speed, precision and effectiveness I get from the answers in this forum and particularly from you guys/gals. You make me feel like I have a personal support team!

MANY MANY THANKS.

So far I've tested granting MANAGE_EXTERNAL_STORAGE and downloading to ASD w/o Write permission and both work flawlessly and with a minimal learning curve

As soon as I have a final, working app, I'll make sure to post it to the gallery to, hopefully, help others.

1 Like

The ASD with the compiled app is:
/storage/emulated/0/Android/data/appinventor.ai_<yourEmail>.appName*/files/

In my case for example:
/storage/emulated/0/Android/data/appinventor.ai_bodymindpower.Relax/files/

So you should not hard-code the ASD, but leave it to AI2 (File component or one of the many extensions for it). And if you want to manually copy the CSV file there, make sure you select the correct ASD.


(*) More precisely the projectName (Relax.aia in my case)

1 Like

@Taifun @TIMAI2 @Anke @ABG @Kevinkun @ChrisWard @Patryk_F

Dear all, thanks so much for all your help during this development!

I've posted it on Hackster: e-Ink RPM Letterboard

1 Like

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