Question about Files, Scopes and Android Levels (US and EU)

Hi,
Here is some of the blocks you demand, Anke
Building the system (write a file to Testsystem)





Read the file into the system subsequently






I don't know of these 'printscreen' pictures gives anything, but you say, that scope 'Legacy' (and scope *APP') works on all phones (only on my phone the scopes works as I describes, apparently)

So post a simple test aia (as small as possible!) and the relevant blocks.

grafik

You try to read from the Private directory (internal storage) since you set FileScope = Legacy.

grafik

You should learn some basics first, see e.g. here:

1 Like

By the way, this part is no longer up to date:

grafik

I will make a simple aia file and when it's ready, I will let you know
Per

still confused, the AI2 documentation says this:

  • 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.

Of course, you cannot write / read to / from

  • the root directory or
  • an arbitrary (sub)folder

of the external storage on Android 11+. But you can write / read to / from one of the Shared folders using FileScope = Legacy (also on Android 11+).

These Shared folders (for non-media files) are:

  • /Documents
  • /Download

of course :slight_smile:

but you can do this with FileScope = legacy on Android less than 10 ?

In which case, does your statement:

apply ? It does for the /Documents and /Download directories but not for everywhere.... ?

Does Legacy then work in the same way as Shared for Android 11+ ?

I am not being facetious, I really am trying to understand how the various filescopes work for Android 11+

The guidance (from Android) is that we should be targeting Android 11+ practices in our apps, regardless of the version the app is used on.

I think, the confusion are the 2 different file scopes we have

  1. in the Screen properties the DefaultFileScope and
  2. the file scope of the file component

as @Anke already pointed out "endless times" :sweat_smile:, btw. last time was here

unfortunately up to now without feedback from @ewpatton, still looking forward to it...

what we have to do currently (as far as I understand it) to get "it" running on all Android versions is

  1. in the Screen properties set the DefautlFileScope to Legacy to get the correct permissions in the manifest and
  2. set the File scope of the file component to what you need in your app, for example
    a) if you like to store/read to/from shared storage, you set File Scope to Shared
    b) if you like to store/read to/from ASD, you set file scope to App

Taifun

Yes, except for the small difference that when FileScope = Shared is set, the / at the beginning is ignored, so the file is always stored in external storage and not in the Private dir of internal storage (as is the case with FileScope = Legacy is if there is no / at the beginning of the path).

Otherwise (i.e. if there is no / at the beginning of the path) these two scopes work identically.

Example - blocks

1 Like

To get the required permissions. These are indeed the correct permissions on Android < 11, but on Android 11 these are the incorrect permissions because

  1. on Android 11+ there is no longer WRITE permission and
  2. both permissions (READ / WRITE) are not needed at all (for the Shared folders).

Since AI2 decided to declare requestLegacyExternalStorage=true in the Manifest (which is only ignored on Android 11+), the storage permissions should be declared basically (always) in all Scopes (DefaultFileScope and FileScope) this way:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />

Note: If DefaultFileScope and the FileScope are both set to App, files are saved in the ASD with the File component. But on Android < 4.4 (< API 19, KitKat) READ & WRITE permissions are required.

In order for these permissions to both be declared in the Manifest, the default settings of the File component must be changed and both permissions must be enabled in the designer. So there is no (recognizable) reason why this option (ReadPermission, WritePermission) exists in the File component at all. Because both permissions are always required on Android < 4.4.

But if you then want to copy/move a file from the ASD to one of the Shared folders, WRITE permission is incorrectly requested even on Android 11+. This permission is

  1. no longer available on Android 11+ and
  2. is not required on Android 11+.

Can anyone make this even clearer? I wouldn't know how! :upside_down_face: :wink:
When even PUs (and apparently even the MIT team :wink:) seem to have trouble understanding all this scope stuff, how will it be with the others?

3 Likes

This is why I have generally been pushing users to saving/storing/retrieving files in/to/from the ASD, which seems to be the most reliable and straightforward location, and to then work from there - either to attempt a copy/move to some shared storage, or just get the file off the device online somewhere.

Yes, but even with that, on Android < 4.4 (with the default settings of the File comp.), you'll have permission issues, as I explained earlier. Only not if both storage permission are enabled in the File comp. (in the designer).

This is only irrelevant for Kodular, because the minSdkVersion is 19 (Android 4.4, KitKat) there. But with AI2 the minSdkVersion is 7 (Android 2.1, Eclair).

:frowning: sigh....

Which really shouldn't make much sense.
Who on earth is still using Android 2.1 (→ Oct 2009)?

IIRC @ewpatton reports @ 4% of users....(or that might be 4.4.2 and below...)

It's never 4%, I'll bet on that. Btw, Google hasn't supported Android 2.1 since 2017:
https://www.mobilescout.com/android/news/n95920/Google-drops-support-Market-Android-21--below.html

Hi,
Now that I have followed all Your (Power Users) discussions around my questions about, "Question about Files, Scopes and Android Levels (US/EU)", have I become much wiser.

So, I have updated my system (according to Taifun's and Anke's informations) and now it's all working very well.
Although, I don't find the information about 'Scopes' in 'AI2's GUIDE' under 'File?/more information':
"File: Non-visible component for storing and retrieving files. Use this...",
particularly readable.
By that I mean, everything that is said about 'Scopes' and 'Default Scopes' isn't written, so everyone completely understands it or it's because I'm not American.

But thanks Taifun and Anke for your help, it was the right solution for me anyway

Per

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