Data / Assets Storage on SD Card

mjtaryan

Active Member
Licensed User
Longtime User
One ofthe apps I'm working on has a "ton" of data and assets (sql, text and image files). I'd like to be able to either force the whole app (including the Files folder) to install on the user's SD card or to at least force the contents of the Files folder to be installed on the SD card. So...

1. Is it possible to force the app to the SD card during installation? If so, how?
2. If #1 is not possible, then can I store the data and assets on the SD card during the app's installation? If so, how?
3. If neither #1 or #3 is possible, how can I move (copy and then delete) the files I want to put on the SD card? Thanks.

Also, a related question. over the course of many years I've developed a penchant for being very organized or sructured in where I put my files (i.e. icons go into an "Icons" folder, data into a "data" folder, audio into an "audio" folder, etc.). In order to do this, is all that I need to do is create these folders inside the Files folder? And, then, how do I reference them when I want to retrieve the files? Thanks for this too.
 

mjtaryan

Active Member
Licensed User
Longtime User
Thanks Erel. For a better understanding on my part, however, I need some elaboration on the folloiwng

1. Storing only the "data" on the SD card -- during installation how does that happen (do I have to do it programatically, say for example when the app is started the first time?)?
2. I've compiled a couple of sample apps to the device with the Projects option set to "Can install to SD card." However, when I've searched for them on my device I can't find them on the card? Why is that (I've used "Root Explorer" as well as a general user file management tool)?

Thanks.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
By marking this option, the app (code and assets) will be installed to the external storage by default. Note that the external storage might be a different storage than the sd card.

Under Setting -> Applications you can see whether an app is installed in the internal storage or external.

Ok, but if I want to install the app to internal storage but put the included data files on the SD card, how do I do this? For example, I want to install MyApp internally and store the data to mnt/SDcard/MyApp/<data> where <data> is various subfolders each with its own type of file. I don't want these to be embedded in the .apk file for the app.
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Another option is to download the files from a file hosting service when your app runs for the first time.

BTW, why do you want to install your APK in the internal storage? The performance will be the same.

Actually, Erel, I guess I don't have a good reason. I guess I'm sort of on autopilot in that most of what I've done in the past (larger systems) installed the software on the machine and large data files on external media. Then, too, I'm wanting to learn all the various options for handling files with android, for example being able to create both directories and files and delete them as needed. I understand that I can't do this with the assets folder .(?)

And So I also have a related question. How do I specify the path to a file? Let's say, for example, that I have created "MyDir/Names" under DirRootExternal and I want to write a file to that location such as File.WriteList(Dir, "MyFile.txt"). How do I specify Dir? All the examples I've seen use only DirInternal, DirDefaultExternal or DirRootExternal and provide no help with respect to specific directories and subfolders. Thanks.
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Keep in mind that using DirRootExternal gives special permissions to the drive so that you can access it. I use a lot of static paths and in that case to get the permission I just call the DirRootExternal and assign it to a Dummy variable.

Dummy = File.DirRootExternal

You could save the file from above with:

B4X:
File.WriteList(File.DirRootExternal, "/MyDir/Names/MyFile.txt")

Depending on the device, because some have different paths, you could also do:

B4X:
File.WriteList("/mnt/sdcard/MyDir/Names", "MyFile.txt")
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Keep in mind that using DirRootExternal gives special permissions to the drive so that you can access it. I use a lot of static paths and in that case to get the permission I just call the DirRootExternal and assign it to a Dummy variable.

Dummy = File.DirRootExternal

You could save the file from above with:

B4X:
File.WriteList(File.DirRootExternal, "/MyDir/Names/MyFile.txt")

Depending on the device, because some have different paths, you could also do:

B4X:
File.WriteList("/mnt/sdcard/MyDir/Names", "MyFile.txt")

Thanks, Margret. That's the info I was looking for.

Mike
 
Upvote 0
Top