Writing data in a .csv file not working

Oh ok, good to know, thanks

Could you create it in your ASD ?

If yes, try deleting the file in the Shared storage, then moving the file from ASD to the Shared storage using some extension.

What is the ASD ?

Application Specific Directory

It is located at

/storage/emulated/0/Android/data/<package_name>/files

Sorry, I tried to understand and search what you are explaining to me but I am lost (this is the first time I do programmation and work with a computer and I am a bit lost).

From what I understand, the following error come from the fact that the path does not exist :

image

So your proposition is to create a place or a path in my storage for the App :

Is that right ?

Which is how I showed it in my post above

Saving the file to just /myfile.csv (with the single slash) will save the file to your default read/write storage area.

On earlier android versions this may be to /storage/emulated/0 but on later versions Android 10+ (API 29+) it will be to the ASD - /storage/emulated/0/Android/data/<package_name>/files.
Earlier versions can use the ASD but you would need to target it with a path.

It is all very complicated...here is a good resource on what is happening:

I would always recommend you work to the dictates of the latest API, and keep things simple by using the default storage location.

Yes.

Next, use a File Extension to move it to the File Path you want keep the file.

Yes indeed, I use your blocks and have the following error :

I guess so this is why @SHUBHAMR69 explain to me to creat the place/path. Where can I find the File Extension you are speaking about ?

Show your current relevant blocks please

And please advise of the Android version you are using to test, and are you testing with companion or when compiled?

1 Like

Here is the block (which is fully copied from yours) :

image

I ame testing when compilided. What do you mean by "And please advise of the Android version you are using to test" ?

What is the android version of the device you are using?

Android 6,7,8,8,1,9,10,11,12 ?

I checked, it is a 12

I have compiled and tested my simple example on Android 12 and it works fine, creates the file and appends to it, so i am not sure why it does not work for you.

Are you trying to create the file Displacement_check_data.csv earlier in the blocks?

Ah...ok

No, this is the first time it appears in this final block. I can put again the whole code : Last_Version_V5_with_ON_OFF_and_SAVING.aia (241.8 KB)

Then maybe it come from my manner to print values in the file which doesn't works

I see earlier in the topic you changed filescope to Legacy. filescope should be set to App in Screen1 designer and anywhere else in File component. No need to give/request read or write permissions if working on Android 12, in order to use the ASD.

Yes, as you say I changed Filscope to Legacy in Screen1 but also For my file component

Change filescope to App

You should not need either of those extensions.

Hello Arthur

The file is being saved in the App's Private directory, so nobody can actually see it unless they have a security-breaking (often PC-based) program.

There is a lot of good info on the forum, but much of it concerning files and similar is not recent enough to cover the latest Google Android Security Measures - even the hint for the App Inventor Create File Block is unfortunately wrong.

Do you like the idea of cutting-out the middle man (TinyDb)? What is the CSV for - is it going to be distributed to others? If so, it will need to be saved in a Shared folder. If not, it's already being saved in the right place.

Ok I understand. What do you mean by "Do you like the idea of cutting-out the middle man (TinyDb)?" ?
The CSV is indeed intend to be distributed after (sharing it by mail for example, if this is what you asked)