File .Exists gives runtime error in Android<4.4, if the File component doesn't requests read/write permissions

You must set DeviceFIleScope = Legacy to declare WRITE permission in the Manifest on Android < 4.4. And I did that in my test apps.
So this is a bug. @ewpatton

Btw, my extension "MFile" does it (does declare READ / WRITE permissions in the Manifest).

I will double check, but it should be sufficient to check the WritePermission property on the File component to get the permission added to the manifest.

Obviously not (on Android < 4.4).

  1. I2 + I3 does nothing without blocks or with I6. No storage permissions are declared in the Manifest.

  2. If DefaultFileScope = Legacy is set in I3, READ/WRITE permissions will be declared on all Android versions (i.e. WRITE also on Android 11+, although it no longer exists there, and READ also on Android 13+, although it no longer exists there exists).

  3. Regardless of whether I1 or I2 was used/set, storage permissions with blocks as shown in I4 and I5 are generally declared in the manifest. Namely under I4 as follows:

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

and under I5 as follows:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  1. If DefaultFileScope=Legacy is set in I3 and the blocks in I4 are used, the permissions are as follows:
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Even for “permissions experts” like me, this is hard to unravel; no one can understand it anymore.

Declaring storage permissions in the manifest depending on the blocks used is quite plausible. However, this becomes unnecessarily complicated, not least due to Google's changes to storage permissions in recent years. However, it has been known for many years that storage permissions are also required for the ASD on Android < 4.4. In this respect, they must generally be declared there (i.e. under API < 19) in the Manifest.

In addition, it makes no sense at all why READ permissions are declared differently under FileScope=Shared than under Legacy. READ permissions for external storage must also be declared for FileScope=Legacy under Android 13. In other words, the permissions declared with FileScope=Shared would also have to be declared with Legacy.

In case it helps to troubleshoot, mi experience is:
Maybe it works in the morning and doesn't in the afternoon.
Same as the need to edit the download link for old devices, to delete the "s" from https://. Most of the times I need to do it, but there are other times when I forget to do it, and scanning the QR works. ¿Or may be the border is in Android 4.4 (some of my old test devices are 4.1 and some others are 4.4.4)?
Thanks

So I have been looking into this and it appears the code that performed this logic has since been removed. I am trying to figure out how it can be incorporated back into the buildserver to re-enable the functionality.

This is a different issue than the permission issue. Our servers are running out of Google and Google manages the security certificates. As time passes and older technologies are deemed insecure they drop support for those algorithms altogether. Your older Android devices likely are unable to understand the newer SSL algorithms and so they won't connect over HTTPS. I will talk with the team about whether we want to offer an HTTP option somehow.

I'm afraid it's not only in Android<4.4
Today I bought a brand new tablet (Android12), installed my app and discovered that File .AppendToFile doesn't create the ADS/files path, nor writes the file.
All scopes are set to App by design. File is not set to request permissions (as I understand it's not supossed to be required to work in the ASD in Android>10).

Postdata:
Afterwards I discovered that, for some reason, in this new chinese tablet that I bought quite cheap, in order to refresh the view of the files of the device's ASD from the pc's file manager, it's not enough to unplug and plug again the USB cable... I need to restart the tablet.

On Android ≥ 4.4 (API 19) as I already said several times!

Post the aia and your relevant blocks.

OK.
Anke, Your app works.
But when compiled today, it's saving the file somewhere else.
Not where it should, at:
Este equipo\pad5max\Almacenamiento interno compartido\Android\data\files.
I can't see this path in the file manager of the pc (connected to the tablet via USB)

This path does not exist
It looks like you are talking about the ASD, which would be /Android/data/<package name>/files

Taifun

Yes, sorry.
You are right

I meant I can't see "<package name>\files" at "Este equipo\pad5max\Almacenamiento interno compartido\Android\data". (This path with the back slashes is the way the file manager of the pc shows the path to the ASD in the tablet).

This

is the root directory of your internal (emulated) sdcard, also known as /storage/emulated/0
The complete path to your ASD is
/storage/emulated/0/Android/data/<package name>/files

Taifun

Right.
The question is with scope set to App, the File .AppendToFile or File .Exists, or File .SaveFile blocks used to create this path and write the file there (which I could see from the pc).
But if you compile the same app now, they must be writing or reading the files from somewhere else.
After running Anke's app I can see other apps ASDs, but not their's.
imagen

It looks like you are only able to see a few subdirectories of /Android/data, but not all of them...

Strange, my understanding up to now was, that after connecting your device via USB to your computer you should be able to see all subdirectories...

Maybe this can help

Taifun

Did you enable the "developer options" on you test device?

1 Like

That was the key. Thank you Anke.

I forgot to enable the developer options, because it's something you only need to do once, when you start using a new device.

Now I can see all ASD folders

image

One more hint.
Before enabling, I could create new folders in the device from the pc, but I couln't rename them. But now I can.

You are right.
My mistake was: If you don't see them, doesn't mean they are not there.

Sumarizing.
To see from the pc file manager the subdirectories of /Android/data (the Application Specific Directory, or ASD) that your app uses to store certain files in the Android device where it is installed (not the assets compiled with the app, nor the companion), you need to:

  • Connect both devices via USB cable (a complete one, which is not only suitable for charging the batery).
  • Set in the Android device, that you want to use the USB cable for transfering files.
  • Enable the developer options in the Android device (just once, for new devices), by pressing several times in Build Number.
  • Optionally, you can set in the pc that you want to open the file manager each time the Android device is connected via USB, or
  • Open manually the file manager on the pc, and select the Android device to see the folders and files at the external storage (Android point of view), or internal (emulated) sd card (device's manufacturer point of view), or whatever the name is. The path will be like this: .../Android/data/<package name>/files

By the way.
Does somebody know a better way to update the files displayed by the pc file manager, other than unpluging the USB cable and pluging it again?
P.D.: In my new device, I even need to restart it, for updating the files displayed in the pc.

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