Problems with storage, reading and writing files after Android 10

I have created an app that allows me to collect data, which is stored in a CSV file. Prior to the release of Android 10, this CSV file was stored on the eternal storage (/APPNAME/data/filename.csv). The app also exported the file to another location from which it could be downloaded onto my computer. As I understand things, Google have now restricted the ways in which apps are able to read/write to storage outside of the app's specific storage directory and, as such, my app is no longer able to read or write to the files that it used to.

I have read on the release notes for nb185 and nb185a, the recommendation is to migrate all files-based storage to the app-specific storage. How should one do this? I was reading up on this and specifically read Anke's post here but when I tried to use the app-specific directory path she provided, it did not work. How do I work around this?

Look at this :

Also read this from Evan:

File Path Updates Starting with Android 10 (Evan's Blog)

1 Like

Have a look to Can not write text file

Thank you for the responses here. However, having looked through the suggestions provided I am none the wiser as to how to go about exporting my files to a directory that is not the app's private directory. The problem that I have is that I need to be able to export the files to be downloaded off the device (specifically NOT using an internet/cloud-based export system - the app is specifically for use in a remote area with no internet access) and so simply writing/exporting to the app's private directory does not help me. I apologise if I am being obtuse here but I need someone to literally spell out for me how to do this.

In addition to this I have another question that has emerged through trying to solve this problem: my understanding is that if I exclude the slash from a file reference (i.e. 'file.csv' instead of '/file.csv') the app will utilise the app-specific private directory for that reference. If that is the case, how can I be sure that the file is actually being written to? I cannot access the app-specific directory on the device and so there is no way for me to check if the file is being modified without having the app to display a list or something similar with the contents of the file after every time the app is supposed to write to the file.

This is my block to read a csv on Android 10, I checked Legacy mode on file1 component


I don't know if it runs on Android 11

It will work on Android 10 and 11 until AI2 targets API 30.

if you store the files in the application specific directory, your app still will work after App Inventor targets API30 in late 2021

no, this is the private directory... the application specific directory is different...
see also

you can, you only have to use the correct path or an extension, for example the file extension (there are also other extensions)

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

Thanks for all these info, it helps .. but I need a little bit more :slight_smile:

HISTORY: The Read File part of my "old" app did not work any more on my new phone (Android 10). Patel's input about checking the "Legacy mode" really helped, thanks :slight_smile: But my issue now is to understand how to update my app for future Android releases.

REQUIREMENT: I only need to "READ" files manually stored on my cell. They all are generated out of Excel macros on my PC. I update / regenerate they from time to time on my PC, before copying them over my cell using a "simple" USB cable :slight_smile:

UNDERSTANDING: Bearing in mind I just would like to keep performing in the future a "call File1 .ReadFrom" as depicted by Patel, and remembering I need to copy my files from a PC to my cell, it sounds like I will need to use a file path on the cell that leads to the app's specific directory. Reading Kodular's "Some basics on Android storage system", I also understand this is considered as "External storage", entailing certain permissions management. I also understand the external private storage "/storage/emulated/0/Android/data//files/" doesn't need the READ permission granting, good :slight_smile:

QUESTION: Is that no-READ-permission-external-private-storage accessible from my PC using a USB cable to copy my files to it? Then, how can I test all this using AI2 companion when no app got generated yet? Easy .. ? :slight_smile:

Enjoy :slight_smile:
Eric

Yes, but how about just trying it out instead of asking questions that are easy to answer yourself.

How should an app or certain functions of an app be tested without an app or any code existing?

Companion is a fun tool. You can quickly test the logic of the program. However, in the end, it's best to test everything on a physical phone. Even for the sake of appearance, because the appearance of the app in the companion differs from that when installed.
It is a pity that the inventor app does not have a style like companion, I like the one from companion very much.

Thanks for your prompt reaction. But I see that not telling you the whole story made it unclear to you, sorry for this.

As a matter of fact, I did perform some testing, which consisted of:

  1. Trying to identify AI Companion's external private storage on my cell using "My Files" app. It looked to be:

  1. Copying one of my own files from my own directory on the cell to the one above (file "Al_DVD-list-1col.prn" as visible above).
  2. Then testing as usual my App with Companion on my cell .. and this worked :slight_smile:
  3. Connecting my cell to my PC with an USB cable and opening the cell's directory from my PC (W10) using the usual Windows Explorer .. and then I got the following :frowning:

So, from the PC, my issue was that I had no visibility on my file "Al_DVD-list-1col.prn", hence my 1st question about being or not able to access a no-READ-permission-external-private-storage from a PC.

  1. Then I unchecked the "Legacy mode" flag .. and my app stopped functioning again :frowning:

So, either that "edu.mit.appinventor.aicompanion3/files" is not AI Companion's external private storage, either it is the right storage, but something else blocks in Android. Either way, I don't gain the knowledge just reading MIT AI's and others' documentation .. hence all my questions :frowning:

Any clue?

NOTE: About your other note "How should an app or certain functions of an app be tested without an app or any code existing?" -> This is not what I've tried to express.

My understanding of AI Companion, wrong perhaps, is that it doesn't compile on the fly but interprets AI's blocks (or something close to this), a little like the BASIC language a "long" time ago :slight_smile: So, my new app not being yet compiled (or "generated" in my previous sentence), there should be no specific app related external private storage yet existing, hence my question "how can I test all this using AI2 companion when no app got generated yet?" :slight_smile:

.. and for this 2nd question, I'm now guessing I'll have to do all this in two steps, one test with the app generated / downloaded onto my cell, but not functioning because using the wrong file directories path, but hopefully having then visibility on the app's newly created external private storage, and a 2nd test after having re-generated the app with the correct file path .. we'll see :slight_smile:

I have no problems with it on my test devices (Android < 10).
Open / double click the folder /data/ to look if it is really empty.
If true, try to copy the file from your PC to that folder.
What version of Android is your device?

I have no access to the ASD on a device with Android ≥ 10.

From the screen shot itself, one can see I had already opened the "data" folder (-> screen shot left hand side: folder "data" is highlighted in grey, and also -> screen shot top side: the path reads folder "data" at the end, which means too I had opened it).

Note : I haven't added to the screen shot that mention "Ce dossier est vide" ( = Empty folder). This came on screen automatically from the W10 utility (French version).

My Android version is 10 (Samsung A40).

About your suggestion of trying copying a file from the PC to that specific directory, I have to tell you that I had the following thought last night before going to bed (I'm in the EU time zone :slight_smile: but didn't take the time to update you:

  1. I thought that, may be, just a supposition, Android didn't grant me a required READ authorization because the PC was considered as being another App trying to access AI Companion's storage. But not getting any authorization alarm/error message left me in the doubt.
  2. So, I had to test the WRITE permission to see whether I'ld receive an alarm this time on my PC .. and I did exactly what you've suggested above: I've tried to copy another file from my PC to that directory .. and the result was that it worked straight forward :slight_smile: Meaning, I did see from my PC the 2nd file now residing in AI Companion's "data" folder .. and my MIT AI app saw it (and used it) as well :slight_smile: .. but all this after having checked back the "Legacy mode" flag though.

Note: From the PC, only the 2nd file is visible. From the cell, both files are visible. So, Android and W10 do manage these two files visibility a little bit differently.

Here is what I can see on my cell, MIT's folder being one amongst several others:

image

.. and here is what I see on my cell, speaking of Android version, just in case your expert eyes would see something:

I now need to learn more on the web, but fear having to handle permissions in all the various steps used to update of my app environment .. :frowning: .. but any help is very welcome of course :slight_smile:

@ejb Try this aia on your device:
(EDIT: aia removed)

I downloaded the video from GoogleDrive twice (Pixel 2XL, Android 11):

Blocks

this might be because of

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

First, thanks a bench to everyone who tries to help me out on that file question :slight_smile:
(I'll read / play the given info and video later when I've time)

Second: I'm in the middle of several things in my life that don't let me enough time right now to work on my app, so, I've become particularly slow and unresponsive to your answers/advices ..

.. but I do remember having another urgent question, this one about setting the exact "Picture" to display as an "Image" (User Interface). In that case, there is no "Legacy mode" flag like the one for READ_files and I got stuck with Android 10 (BTW, I'm on Android 11 now). Since my app has to pick the right image file out of hundreds, and that I add new image files from time to time to the list, I need to specify the path to that image file for the SET_Picture command a similar way to specifying the path to a file for the READ_FROM commande.

So, do we have a similar work around like the "Legacy mode" for specifying an image file path this time?

image

  1. Are you targeting Android >= 10 now (only)?
  2. Where are your image files located on the device? (Android >=10 ?)