Files and Database Must Reside on SD Card. How to Refer To SD Card Root?

Mahares

Expert
Licensed User
Longtime User
My files and database must reside in the SD card in case the device is damaged, I can insert the card in another device without losing data. In one device it is referred to as : /mnt/sdcard-ext. On the other it is : /mnt/extsd. How do I insure that everything is saved on the SD card regardless of the name of the card.
All the while I was thinking that my database and files were stored in the root of the SD card as I use File.DirRootExternal. I removed the SD card and popped it into a card reader but the files are not there they are on the phone memory. I read some threads where the SD card is referred to as File.DirDefaultExternal. So, I removed the SD card from the device and found out that the files and database are not on the SD card either. They are in the internal memory of the device.
Thank you for clarifying.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Both of what you stated should save to the SD Card. Some Devices are starting to have no SD Card though and mapping memory internally. Perhaps your device uses both or something. If you ever do get it to work properly though I'd recommend a high end SD Card (Sometimes called Industrial/Commercial). Databases read and write a lot and SD Cards have limited write cycles. Depending on the database and how good the leveling is on the card to write to all sectors and not the same over and over a cheap one may wear out in a month.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@TDS: I tried the code you referred to but could not get it to work for me. Perhaps Jost Aus Sost can explain a little more on how to insert in a project.
@Roger: On one device the SD is:/mnt/sdcard-ext and on another it is:/mnt/extsd.
I cannot write a project for each SD card name. The database and files must be saved to the card. I have to find a solution to this. Is there something like this???:
B4X:
If deviceID= X then
  Root="/mnt/sdcard-ext"
else if DeviceID=Y then
  Root="/mnt/extsd"
else if DeviceID=Z then
  Root="/mnt/external_sd" then
else if etc...
End if
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
File.DirRootExternal refers to Internal memory not an external sdcard
I tend to agree, but why does Erel refer to File.DirRootExternal as storage card in many of his threads or answers.
My question is always: what do you call the SD card root folder in B4A since I must save all files and databases to the storage card media and not the internal in case the device is damaged, the Sd card can be inserted in another device. I noticed the name changes from device to device. How do you get around that programmatically.
Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.DirRootExternal is equivalent to Java getExternalStorageDirectory.
It is a different media than the internal drive. Many devices have an additional storage card.

This note was added to Android documentation sometime ago:
Note: don't be confused by the word "external" here. This
directory can better be thought as media/shared storage. It is a
filesystem that can hold a relatively large amount of data and that
is shared across all applications (does not enforce permissions).
Traditionally this is an SD card, but it may also be implemented as
built-in storage in a device that is distinct from the protected
internal storage and can be mounted as a filesystem on a computer.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Erel; That still does not answer the crux of my question, which is how do I refer to the SD card proper in B4A. Some devices use /mnt/extsd, some use /mnt/sdcard-ext, some use something else. I cannot just write an app for each device in the entire gamut. I need to store files and databases in the SD card, so when I remove it from the device, the files are on the card itself.
I hope we can come to a resolution.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@NJDude: Yes, I spent a lot of time reading all the posts in the thread you refer to. I tried to implement Jost Aus Sost code, but was unable. Nobody confirmed how you include it in a project or if it works. How can you tell a customer that I cannot save their files or databases to an SD card because I do not know what to refer to it unless they buy only one type of device, as each manufacturer calls it something different.
Thanks
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
@NJDude: Yes, I spent a lot of time reading all the posts in the thread you refer to. I tried to implement Jost Aus Sost code, but was unable. Nobody confirmed how you include it in a project or if it works. How can you tell a customer that I cannot save their files or databases to an SD card because I do not know what to refer to it unless they buy only one type of device, as each manufacturer calls it something different.
Thanks

I just ran this code and I had nothing special to do to implement it. Just a copy/paste and a Log(getSDCardPath).
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Informatix: The problem with the code from Jost Aus Sost does not return the correct name most of the time. I ran it on 3 different devices, all equipped with SD cards. See results below:

I ran it on a 7"tablet with OS4.03. It showed: /mnt/sdcard where it should be /mnt/extsd
I ran it on a Razr smar phone OS4.04. It returned /mnt/sdcard-ext:none:lun1. It is partially correct as the card is: /mnt/sdcard-ext
I ran it on another 7" tablet with OS4.03. It returned /mnt/external_sd which says:file not found exception when I tried to copy a file to the SD using that name.

Maybe you can use some of your expertise and come up with something. How do you do it in your FileExplorer Class and still display files.
Thank you
 
Upvote 0

Robert Grimmett

Member
Licensed User
Longtime User
I am having the same issue, however i have the advantage of writing for a single type of device (i can force the customer to use a certain device in this case) However down the road I can see the application being used on others only because of Moore's law.. is it possible to force install of the application to sd and then read where it is stored.
 
Upvote 0
Top