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

In fact is not only the File .Exists block that gives the runtime error, but any of the blocks of the File component.
The problem is when the error appears at start. So soon that you can't figure out why

Correct. And it is not only the File component but any component or extension that uses (ask for) this path:

Therefore the ASD is created when ever needed (automatically).

But the ASD cannot be created without WRITE permission on Android < 4.4 (KitKat), as I mentioned several times.

1 Like

I was happy because I understood everything....
But here it comes again:
Runtime Error
End Application.

RuntimeError.aia (1.7 KB)

image

image

What am I doing wrong?

You forgot to ask for permission

Taifun

I set by design that File component asks for both read and write permissions.
Isn't this enough?

I did not try that on older devices, so I do not know, if you get the dialog to write files automatically

Try it in a button click event

To save a file in the Screen Initialize event is too early, because on first run of the app the user first has to grant write permission before being able to save the file

Taifun

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