B4A Class Manage External Storage - access internal external storage >= SDK 30

Google seems intent on dumbing down Android to the point of uselessnes to me. I think of my devices as little computers and I want a proper file system on them, not the limited tortuous things that Google offers and that I don't understand, ContentChooser, FileProvider, ... o_O I'm getting old and can't cope with complications like that! :(

So here is a class that lets apps on SDK 30 and higher devices treat the file store as a real file store and not some dumbed down abstracted thing. ?

It uses a new permission that Google will not allow for most Play Store apps.
Manage all files on a storage device | Android Developers
As I will never have apps in the Play Store this worries me not one jot :p


The class uses code stolen from Erel's ExternalStorage class to provide a similar API - thank you Erel ?
ExternalStorage - Access SD cards and USB sticks | B4X Programming Forum

EDIT: Note the minor convenience code modification to Sub GetPermission in the ManageExternalStorage class suggested in post #3 below.
in.Initialize("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", "package:" & Application.PackageName)

EDIT: If for some reason you need to access folders under Android/data or Android/obb there is a loophole in post #35 here. Note that this is probably not intentional on Googles part and may be may closed in the future. If your File Explorer on your device can access these folders this is how it is doing it.
FURTHER EDIT: This loophole now seems to be closed in Android14
 

Attachments

  • ManageExternalStorage_1.00.zip
    13.4 KB · Views: 4,197
Last edited:
Все, что работает с активностями, может работать и с B4XPages. Я не знаком с кодом, предполагаю, что вам нужно изменить Wait For Activity_PermissionResult на Wait For B4XPage_PermissionResult и он будет работать.
Thanks, I fixed it. But the program closes when requested to access files, without error logs!
 
There is always a stack trace + error message in the logs when the app crashes. Sometimes it is in the unfiltered logs.
Sorry. When there's a lot of code, you stop seeing the obvious! It is necessary to register the name of your package in the MES class! It's decided! Thank you.
 

BlueVision

Well-Known Member
Licensed User
Longtime User
A quick update from me (apologies for posting in a “closed thread” – but some things need to be posted at the source, as time flies and the Android operating system is constantly changing...)
First of all, many thanks to agraham for this gem of code. This allows to access “unreachable data” from a non-Play Store app again, and it saved my app from being scrapped for good.
I implemented the code on Android 14 and was immediately able to access the download folder from within the app again. The class has been part of the app ever since, as have the permission requests before every file operation.

The app then ran completely smoothly for a very long time. In the meantime, the operating system underlying the app has evolved from Android 14 to Android 16, so it was time for refreshing the app.
This is where the dilemma began. The new build made with B4A V13.5 did not work. I was completely at my wits’ end because I couldn’t find a solution even after a lengthy search on the forum. There was no error message; the app simply no longer reached the code within the permission requests, as it had done previously.
The solution is simple. Apparently, Google has taken a step backwards. In my case, it was now enough simply to ask for permission when the app started and let the user respond. Any further permission requests at the critical points blocked the code inside the permission request from running. So I disabled those requests, and my code ran as planned again. Crazy...

I hope this will help others when using this class

Cheers, BV
 

Johan Schoeman

Expert
Licensed User
Longtime User
I am also using it on A16 without a problem. For ease of using the apps I created for customers to easily find PDFs and MSWord docs that I create with my apps I need to be able to access Internal Storage. And this class works 100%+.

Not interested in posting it to playstore. Just easy access for customers to get to the created files without having to connect device(s) to a laptop and then start searching for where they files are. All of them in Internal Storage and can with it from there whatever you want (share via email, WhatsApp, or whatever - at least for now up to A16
 
  • Like
Reactions: byz
Top