Hello! There are txt files (Templates) where the variables are written. I want the user to be able to load my templates from the menu. I have not found a better way than putting these Templates in assets.
I got a list of all the asset files and filtered out all the txt files. When you click on a list item, this file needs to be loaded (Readed, in the example). And every time, I get error 2101, the file was not found. But I see that he is there, he is on my list!
Question: how can I get a file from assets?
listload.aia (228.4 KB)
This post was flagged by the community and is temporarily hidden.
have you check it after compiled apk? or checking it only in companion?
and one more thing, we cannot show txt file direct, we must have to read it with file component, or simply store your text to any variable and load that after screen initialize.
let me check your aia if i can do anything with that.
Use // for files in assets
Basically / theoretically as Boban said, but:
It’s really hard to get it working, because there are several issues with the File component:
- Sometimes the full path and sometimes the relative is used (see blocks below)
- WRITE permission is not queried automatically (only READ), so you have to ask manually for WRITE permission.
- Permission granted is not triggered when the app starts for the first time, so you have to reload the screen.
- Moreover: the File component can not access the assets with the APK (works only with companion).
It seems to work! I will check this in full project.
Check with APK.
Btw, this returns:
file:///android_asset/ which will work only for the webviewer component:
yes this one is working only for web viewer, in companion i can read from file with /Makeroid/Assets/filename.txt, but when it goes to compiled apk, txt files goes to “android_asset/” which is not accessible by files component.
yes, and this is a bug.
Just tried // and it is working fine as apk
Since when? Then this bug is fixed, which I didn’t realize. I’ll check that again.
i am also trying something on his aia, but cant compile apk due to (unknown famous error of these day) unable to compile apk without any reason.
what bug are you taking about?
if you want to read a file from the assets using the file component, you have to use two slashes // followed by the filename, see also the documentation Storage
ReadFrom( fileName )
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
Yes // works! Of course, Reading from the file did not work, but I was able to load the data using KIO4_TintDBX1. I tried using KIO4_GetTinyDB1, but there it didn’t work.
I used this blocks for reading from file
Yes that works, but do you have an idea why it’s not working with copy file from assets?