Android Question File.DirRootExternal not the path of the sd-card?

Alexander Stolte

Expert
Licensed User
Hello,

In the theory you get with DirRootExternal the path of an external storage media or sd-card. Is that right?

Because with me comes a completely different path out and try to save something under the path it saves it always on the device not on the SD.

I add this permission to the manifest editor:
B4X:
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")

And writeable is true.

Or is there another way to save the sd card? All tutorials I have read have been based on "DirRootExternal"
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
No. It returns the path to the secondary storage. On 99% of the devices this will not be an sd card.

You can use RuntimePermissions.GetAllSafeDirsExternal to get the path of the only folder that is accessible for your app on the sd card.

There are many discussions related to sd cards: https://www.b4x.com/search?query=sd+card
 
Upvote 0

Alexander Stolte

Expert
Licensed User
I have one more question,

I use: GetAllSafeDirExternal, as a result I get 2 paths. The second path is the sd-card. The Problem is, i cant convert an array to string. And if i use this array, i get errors.

My Code:
B4X:
Dim rp As RuntimePermissions
        Dim folders As List = rp.GetAllSafeDirsExternal("")
        Dim List2 As List
        List2.Initialize
        List2.AddAll(folders)
        List2.RemoveAt(0)

        astream.StreamFolder = List2

Result:
B4X:
(ArrayList) [/storage/0123-4567/Android/data/b4a.testing/files]

Errors:

B4X:
Error: (ErrnoException) android.system.ErrnoException: open failed: ENOENT (No such file or directory)

Permission to write on there is set:
B4X:
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Log(rp.GetSafeDirDefaultExternal(""))
this log the only folder on the sdcard which is writeable for your app. Usually it is the second storage (internal!).

You dont have access to a third storage (External SDCard) starting from android 5 (or was it 4.4?). I may be wrong
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Correct

Edit: if you have setup your device to use the external storage for app-installations then you may get a path on the external sdcard, But again; only THIS one Folder is writeable for your app.
You dont have WRITE-Access to any other folder.

You can for sure READ the files on external sdcard using my STORAGE lib. See https://www.b4x.com/android/forum/threads/donmanfreds-overview.54618/ for a list of my libs... It´s the first i published

See Example attached
 

Attachments

  • storageex.zip
    6.5 KB · Views: 822
Last edited:
Upvote 0
Top