Can I use an SD card for storage Scope Shared in Android 10 and 11

Can I use an SD card for scope shared storage in Android 10 and 11 and if so should I format it as internal memory when installing it?

Does your device offer the possibility to format a MicroSD card as internal storage?
(This is not possible with all devices). If so, why not just try it out for yourself.

Not all devices have an SD card.

Read the App Inventor File documentation here.

Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single / will be read from and written to the root of the external storage directory, e.g., /sdcard/. Legacy functionality will not work on Android 11 or later.

1 Like

Thanks for the reply Gordon. Yes I agree and sd cards tend to be found in older phones as the newer ones have larger built in memory. The reason I come across sd cards is when I try to recycle an old phone that is no longer supported by the manufacturer and I choose to reuse it as a controller, where the sim card and internet connection are no longer needed.

Cheers, Peter

Thanks for the reply Johannes.
I had configured the sd card as an internal unit and have been using the attached app
T1File1.aia (35.7 KB)
to test the excellent file block set and instructions at
http://ai2.appinventor.mit.edu/reference/components/storage.html. Everything seems to work except for the directory block which doesn't read external directories selectively instead providing a complete external directory and file list. Also and more importantly for me, the read file block works for a while on any given file but then after several repetitions sometimes fails, with the message "Error 2102: The file Documents/filename.txt could not be opened".

I've checked that:

  • the scope is set to shared and the directory is either download or Documents
  • the file has been written properly i.e was not trying to overwrite a file with the same name
  • the file exists instruction shows that the file is in the directory and is a text file
  • the file is actually in the directory because there is an android bug that doesn't put it there immediately after the write instruction until the phone has been switched off then on. I'm still assessing this and will let you know how I go.
  • I'm currently checking if a trim instruction on the composite file name removes the problem

My question about the SD card was just one more check, as the sd card is shown separate from the internal file structure in one of my file managers, even though the card has been formatted as internal. So is it possible the Android 10-11 file restrictions disallow SD cards for file sharing read-writes?

Any thoughts on the appropriateness of sd cards for Android 10 and 11 would be appreciated, Cheers, Peter

Use the TaifunFile extension to get the available storage directories and post the "Do it" result:

grafik

Since the file component uses a relative path, it should not be possible to write to or read from this directory (MicroSD card, used as internal storage) with the file component. With the EFile extension from @vknow360 you can also uses an absolute or full path. In this case, try the full path (file:///storage/...).

See also here:

2 Likes

Well, these older devices certainly won't have Android 10 or 11. And therefore you have unlimited access to a MicroSD card that is used as internal storage (also to its root directory). Of course, you need READ / WRITE permissions for this. In order for these permissions to be declared in the Manifest, DefaultFileScope = Legacy must be set in the designer.

In other words, the Scoped (Shared) storage is only relevant on devices with Android ≥ 10.

Btw, strange that these questions about using a MicroSD card as internal storage have not yet been asked in this forum. Or did I miss something?

1 Like

Hi Johannes,
I don't think you missed anything. I had checked everything I could find on shared files for Android 10 and 11, but couldn't find a clear explanation for the role of sd cards. Fortunately, the issue is solved now and thank you for your comments and suggestions.

The phone tested was a Nokia 2. It had Android 10 installed and required an sd card formatted as internal memory. All the test files were either new or renamed and not copied over and none of them commenced with either 1, 2 or 3 forward slashes (/). In the designer the legacy mode was not activated and the scope and read/write permissions were all preset to app or shared. The files were all text or csv files, so that they could be written and read to Download or Documents folders but not other folders. That limited capability is OK for me as I designed my Apps for the A10/11 changeover two years ago and just spotted last week that the MIT AI file blocks had been upgraded, so now the changeover for Android 10 is complete. Hopefully, Android 11 will also work when it arrives!

The intermittent read operation problem was because I was downloading files using a USB connection. Using Google Drive instead the problem goes away as Google Drive allocates files to its own folder called 'Download' inside the 'Downloads' folder.

In conclusion, it was possible to use Android 10 with an sd card configured as internal memory for downloading, reading and writing shared files using the shared storage scope; so long as I used Google Drive to download files from my pc to the Android phone.

Many thanks for your comments, regards, Peter

Just an update - The sd card with Nokia2.1 and Android 10 is still able to read and write to shared storage. However, I note that it is necessary to use the read and write permission request blocks the first time the App is used. The tick boxes for read-write permission are not enough.

Also I tried the same app tests on a Nokia 5.4 with no SD card and it was unable to read or write text files to the Media folders Download and Documentation. I've taken this up in a new topic " AI2 Files block - shared scope file storage cannot read / write text files to media folders

I've copied the revised App below, Cheers, Peter

T2File1.aia (32.0 KB)

2 Likes

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