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


This simple app works well in companion and when built and installed in one of my devices with Android11. But when built in other device with Android 4 it gives a runtime error (If somebody wants to try, please remember that It's necessary to edit the build link to delete the "s" from https://)


Arranque2.aia (2.3 KB)

and the runtime error is ?

All it says is:
Runtime Error
End Application.

This most likely that the ASD is not created on Android 4. You will need to create it, either manually or using one of the many extensions that can do it.

That is true.
Just by installing an app, it doesn't create the ASD path (neither in modern versions of Android)
I tried that the app creates the path itself at first start, by writing a log file.
But I'm having problems with the instructions of the block File .SaveFile.
They seem not to be updated.
For instance, the place where instructions say the files are located by companion is wrong:
It writes the file at Android/data/, instead of at AppInventor/data


Ignore the tooltip, as you say, it is out of date.

You do need to use the slash (/), though.

Do you mean to put a / in front of the file name at File . SaveFile?
Only in Android<10 or always?

Should be always, otherwise the file will be saved to the private directory

Please explain to me what you are talking about here. I do not understand anything. Where does this file come from? How was it stored there?

Try this one:
Arranque2a.aia (2.6 KB)

Build the APK and check it...
Tested on Android 4.3.


Yes Anke. Your app works fine (I tested on Android 4.2.3).
The key is, your app at start first writes the file (at the device's Application Specific Directory (ASD), which automatically creates the path), and only then asks if the file exists.

It works even without the need of the File component asking for permissions, and without forcing programatically the File scope to App (It's enough to set it by design).
I also checked that File .Exists can even be called inmediatelly after saving the file (or also using File .AppendToFile, which creates the file if it doesn't exist yet). There's is no need to wait and then pressing a button.


It seems that (as Tim said) the runtime error happens (at old Android versions only) when File .Exists block is called and the ASD path is still not created.

Thanks both for your help.

... if we believe the out of date tooltip instructions, dated before the modifications in scope due to Android10

No. It doesn't matter whether the ASD exists or not.
Try this one: Arranque2b.aia (2.6 KB)
build the APK and check it (on your Android < 4.4 test devices).

Dangerous permissions (like storage p.) on Android < 6 are requested and granted at install-time (and not at run-time).

Note: On Android < 4.4 (KitKat, API < 19) storage permissions must be declared in the Manifest to be able to request and grant them at install-time.


Wow! You're right.
Making the File component request read/write permissions by design, also avoids the runtime error of the File .Exists block, without having to first use the trick of making sure to create the path to the ASD by writing to a file.

Now that you seem to understand it, change and close the topic.

Which, by the way, also requires storage permission (WRITE).

Thank you very much for your socratic questioning method, which helps us to learn

1 Like

I thought this permission is only required for writing outside of the ASD ¿Right?

Yes, but only since API 19 (KitKat, Android 4.4).
I changed it in your topic.

1 Like

By the way: The block File .Exists, when called, also creates itslef the path to ASD/files, in case it doesn't exists (tested in Android 4.1.1 and 13).
That is why asking if exists with an empty text at File .Exists path, always answers true.