Android Question Android Folders access .. again..

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to All
I know that this topic is widely treated in this forum. So widely that I didn't understand how I can solve my problem. So, forgive me in advance. I need a user to put files in a tablet, and read them with my App. Not a Google Play/Store app. To do this, the user connects the Tablet with an Usb cable to a computer, and saves the files. After that, my app should allow him to choose what to read etc. Where to do this? The Download folder (or the Android/App/Data/Files folder) seemed the right choice, but we know that it is impossible now. I mean: we can save files there from a computer by usb cable, we can access them, but .. we cannot choose which one to access with a FileDialog.. (or am I missing "something" ?; usually my first option...). Worse, the problem seems to be that no folder is available, for my purposes. I did a test program with the actual version of B4A. It opens the Download folder, showing nothing, despite there are some files. I tried to downgrade the Android Target Version to 29 with no result. The ".." indicator of the file dialog simply doesn't work in this case, while with actual version made by the B4a ide, namely 33, at least appears the (useless) list of folders. Useless because no one of them is accessible. Moreover, i don't see where and how the user should be prompted to ask for accessing a folder, as I read in other posts on this subject. Sorry if I am rather confused.. Thanks for reading..
 

Attachments

  • TestFileDialog.zip
    10.3 KB · Views: 52

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
The thing is you can get files from the download folder using ContentChooser.
However, the user must select the files. It is not enough for the app to have access to the folder.
I am not sure if it is possible for the user to provide permission to access at the folder level anymore. Perhaps someone else can answer that one.

I think this is the point you are struggling with.

What you need to do is have the user select the file(s) again from the app (use ContentChooser for this). You will now be able to access them in the app.


This all works fine with API 33.

Hope that help to clarify the situation.
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Thanks. Just tried. Curiously the SaveAs goes by default to Download folder, exactly what I wanted for Load. With this latter.. i don't see the possibility to access the download folder..
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Of course i tried, because I am only interested in Loading. I have a ".dxf" file in the folder Download. After first screen, I can select another App to use, and I select the "My Files" App (sorry, because here appears in local language, not in englsh). Then a title appears on top with some buttons (a tab control). On one I see "Download".. I click on it, but nothing happens...
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. I have verified that things are different from what I was thinking, and I think I must fix the situation, in case somebody will have same problem.
I did other experiments, using:
B4X:
    Dim WorkDir As String
    Dim z As List
    Dim rp As RuntimePermissions
    WorkDir = File.Combine(rp.GetSafeDirDefaultExternal(""), "Test")
    z=File.ListFiles(WorkDir)
Here "Test" is a folder inside "/storage/emulated/0/Android/data/b4a.example/files" i.e. the folder created by Android for the App, in this case "b4a.example".
While the folder "Download" managed by the OS is not accessible, the folder "/storage/emulated/0/Android/data/b4a.example/files/Test" is. BUT this directory is accessible only with the computer connected with an Usb cable (Btw Not with the file explorer App in the Tablet.....). So my problem can be solved using a directory inside the "Android/Data/AppName/Files". The user may load files there, with the computer and the App may use and access them. It will be necessary to make a Dialog to list the files and choose which one, of course. Maybe DonManfred's WildCardListing code (if I remember well) will be helpful, despite probably overkilling in this case. Finally, for my needs, this seems to be enough, but only because I load the files with the cable.
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
The answer
The Load works differently from the SaveAs. Totally different. Thanks a lot. Have a nice evening.

It works totally different! however it IS THE ANSWER! the thing you are missing is "THE USER MUST MANUALLY SAVE SOMETHING TO THAT DIERECTORY!" in order for YOUR APP to GAIN THE PERMISSION to LOAD FROM THAT DIRECTORY!....
 
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
It works totally different! however it IS THE ANSWER! the thing you are missing is "THE USER MUST MANUALLY SAVE SOMETHING TO THAT DIERECTORY!" in order for YOUR APP to GAIN THE PERMISSION to LOAD FROM THAT DIRECTORY!....
Yes, this I was missing: how to gain permission. I have read about this mechanism, but I didn't realize how to apply. I can try to use this trick. Thanks a lot.
 
Upvote 0
Top