Android Question How to use File.DirRootExternal for reading?

coupe70

Member
Dear forum experts,

I have some programming experience, but I'm new to B4A and programming for Android.
I have a quite simple app. It listens to UDP and whenever it receives ANYTHING (for the moment), it starts an mp3 with Media Player.
This works fine with File.DirAssets, but I would prefer to just put the mp3 on the phone and use File.DirRootExternal.
I understand that File.DirRootExternal is the internal memory of the phone and not the SD card, but I got error messages
that lead me to the vague conclusion that the file cannot be accessed - not, because it does not exist, but because of missing
permission.

I found out that when I manually give the installed app the permission to access memory in phone settings, it works.

So I searched for a way to do this automatically or at least make the phone ask for permission and found this to be added to the manifest:
B4X:
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="19" />)
But it doesn't work.

Can you please provide some help?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
So I searched for a way to do this automatically or at least make the phone ask for permission and found this to be added to the manifest:
This has nothing to do with File.DirRootExternal.

It is no longer possible to directly access File.DirRootExternal. The best way is to use ContentChooser.
Important example: [B4X] TextEditor - Save and load external files
 
Upvote 0

coupe70

Member
This has nothing to do with File.DirRootExternal.

It is no longer possible to directly access File.DirRootExternal. The best way is to use ContentChooser.
Important example: [B4X] TextEditor - Save and load external files
So content chooser would be opening a file dialog to manually choose a file, right?
No way to automatically load data?

And what do you mean by "no longer possible"? It actually works for me after manually giving permission....
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
And what do you mean by "no longer possible"? It actually works for me after manually giving permission....
It depends on your targetSDK setting in the manifest. For 30 and later access to File.DirRootExternal is not allowed, and Google mandates this for Play Store apps. For your own use keep targeting 28 and it will work fine or you can use my ManageExternalStorage class for targeting later SDKs.

Details of changes for various target SDKs are here. If Erel reads this perhps he should consider an update for SDK 30 limitations.
 
Upvote 0
Top