Hello, I'm trying to build an app where I can browse a file (.csv) from the phone, and then display the contents in a label.
The app works perfectly fine when using the AI Companion, but when I build the .apk and install the app on my phone, I get the following error:
Here are my blocks that i used to test the apk (not the full app that works on the companion, but the block that's causing the issue):
Any idea why this "PathFromUri" function works on companion but not apk? and how do i fix it? This is using the FileTools Extension by Sunny.
This was tested on android 11. it works for android 9.
Where does the CSV file come from?
If the file comes from the external storage (e.g. /storage/emulated/0Download/file.csv) it only works if the user grants manually → MANAGE_EXTERNAL_FILES permission:
This permission is declared in the Manifest if you use the FileTools extension from @vknow360.
The TaifunFile extension from @Taifun does not declare it.
So
grantMANAGE_EXTERNAL_FILES in the app settings and try again and / or
try to move the file from the external storage to the ASD an open / read it from there.
@Anke the CSV file comes from the external storage, it could be from /storage/emulated/0Download/file.csv or from any other external folder on the phone.
The app allows the user to browse a file (CSV and txt), and then display the contents in a label.
the whole app works on the companion, but not when building the actual apk..
I haven't gotten to the part of reading the file yet, it does work on the companion (I did have to copy the file to the ASD and then read it from there, for android 11, and did read it the traditional way for android <11. I can include the blocks but that's not the problem I'm facing in the apk (yet?) ).
Are those permissions that you mentioned also responsible for the PathFromUri function? because I can't get to the "Read File" part without getting the file's path.. I've researched how to edit the manifest, I found your guide here https://community.kodular.io/t/how-to-customize-the-manifest-example-companion-apk/68677 . Will try it and post the results soon..
Yes, but also for all files (non-media files).
For media files you only need READ permission to access those files.
But for non-media files (like .txt or .csv), that are not created by the app you need MANAGE_EXTERNAL_FILES to access those files if they are stored in the external storage (outside of the ASD).
Of course, and I didn't say that this is a solution.
I just wanted to show one way how it would work. It is clear that this is not an option for an app that is to be published in the Play Store.
Yes, it remains to be seen whether this will be implemented in AI2 ...
@Anke The file comes from the user. Basically, the file is a route to use for navigation.. the user creates his desired route (outside the app, using a website) and then downloads the route file to his phone. where the file ends up being, I don't know. I don't know the file's name either.. the app should be able to work with that.. (as any other normal app would). the user should be able to browse his phone's file (open the file manager from the app) and then select the file. then display the contents in a label, for starters..
@Taifun I did end up succeeding in reading files from the external storage, both on android 11, and on android 9, using your help and @TIMAI2 help from the previous thread I posted. However, this only worked on the companion... when I compiled the .apk, it stopped working, mainly because of what I mentioned in this thread (the "PathFromUri" function isn't working for android 11) but this function worked for android 9, though the "ReadFrom" function to read the file, was unsuccessful (on the apk).
Here's the situation again, for now:
On the companion:
I managed to read files from external storage, regardless of where/how the file was created. both on android 11 and on android 9 (so all SDK?). the whole app works as desired.
Compiled .apk
On android 11, the "PathFromUri" function isn't working, so I didn't even get to try to read the file because I can't even get it's path. so i need to fix this, before moving on to test the "ReadFrom" function to read the file..
On android 9, the "PathFromUri" function works. however, I haven't succeeded yet to read the file because I believe the response from the "FileCopied" isn't successful. so there's a problem with the "CopyFileAsync" on my android 9..
I posted all of the blocks in the previous post. It should deal with both android 11 and 9 (SDK above 29 and below..)
But here it is again, with a few notes:
The path is correct on android 9. it's the CopyFileAsync that's not working as intended. Do you mean the path that's used as the source for the CopyFileAsync? this is the path that I get:
On android 11, I cannot even get the path, using the "PathFromUri" function. it's returning nothing..
I cannot control the param that's returned as a response I believe.. it's returned from the "FileCopied" function.. I tried it as a boolean first, but it returned an error, so i displayed it as a text and saw the value it returned (which is copy successful if the file was copied successfully).