Reading CSV in App Inventor

Hello everyone:
I know there has been a lot of discussion on this topic, but I am very inexperienced and don't understand it.
What I need is for my app running on Android 10 to read a CSV file, comma separated, that is in the Documents folder and write it to a label. I have tested on older phones and I get it but not with Android 10. I have tried with Efile and not either.
Can you help me?

image

Thanks!

How does the file get to the "Documents" folder ?
Does the file need to be in that folder ? (could it be stored somewhere else ?)

It can be stored in any folder.

Well, for Android 10+, the easiest place to store files is in the app's application specific directory (ASD) where the user has read/write access. Then you can use the built-in file component to read/write the csv file.

/storage/emulated/0/Android/data/<packageName>/files/...

You can get the above using the makePath blocks in the file component

Where does this file cone from? Created by another app during runtime? Starting from Android 11 you need SAF to read it, sed also the overview here Some basics on Android storage system - #34 by Anke

Taifun

These are data provided by me. They come from an Excel file that I transform to CSV format.

Are these static data, i.e. you generate it only once to then use in the app? If yes, upload the file into the assets of your app (media section) and read it from there

Taifun

1 Like

the file does not always contain the same data.

Ok, which means, during runtime of your app you generate a csv file from Excel and want to read it in your app.

To be able to do this for all Android versions, you have to use SAF...

Taifun

It's so easy what I want to do, I'm not explaining it well.
I have a csv file that I generate on the PC. For example:
2,APZU3805498
3,BEAU2794838
4,CMAU0769155
5,CSLU1139924
6,CSNU6261439

So I just want to read this file from the app and put it in a label.

The folder has to be accessible.

One way

  1. maintain the csv file in a Google Sheet or a CloudDB or a FirebaseDB etc. online instead of in a folder on your PC. A Google sheet can be updated using an app to modify the data or can be accessed directly by you PC.
  2. Read and download the csv from the Sheet or database to your app as a List or a csv and place it in a Label.
  3. Use the data in your app.

If your app is only for private use you can use this way
How to request and grant MANAGE_EXTERNAL_STORAGE permission.

1 Like