Backup Files

JonPM

Well-Known Member
Licensed User
Longtime User
I have many files within my app that get moved to DirInternal on install. I would like to offer the option to backup these files if the user decides to uninstall the app, or (like several who have emailed me) for users who wipe their phones/devices frequently. My question is where is a place that I can backup these files too that won't get deleted if a user uninstalls the app? I plan on offering the user the option to backup to Internal memory and/or External. I am guessing I would need to use MakeDir, but I'm not sure where a safe place for the files are. Can anyone help?
 

margret

Well-Known Member
Licensed User
Longtime User
You can most times do something like this: File.ListFiles("/mnt"). This will show the directory structure of the device. On my device I see directories like:

/mnt/media
/mnt/sdcard

You can then make a directory like you App name on one of these like:

/mnt/sdcard/myappname/backup/data

Then copy all the data to that directory. If the user uninstalls your app this directory will not be deleted.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User

Awesome, thanks! What is the directory for internal memory? I am assuming not all devices have sdcard or an external memory drive.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Another question, if I do this:

File.MakeDir(File.DirInternal,"backup/2012")

Will this subfolder and its content be erased if user uninstalls?
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Yes, they will be erased in that folder. DirInternal give the APPs internal directory. You would need to do something like:

Updated, previous syntax was wrong
B4X:
File.MakeDir("/mnt/media", "yourappname/backup/data") 'Nook - Internal
File.MakeDir("/mnt/sdcard", "yourappname/backup/data") 'Kindle Fire - Internal
File.MakeDir("/mnt/sdcard", "yourappname/backup/data") 'ASUS Eee Pad - Internal
File.MakeDir("/mnt/Removable/microSD", "yourappname/backup/data") 'ASUS Eee Pad - External

This will be created outside your apps folder and in the root of internal/external memory and will not be erased if your app is uninstalled.
 
Last edited:
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Hmm, actually I am running into problems. Here is my code:

B4X:
File.MakeDir("/mnt","appname/My Backup")
Log(File.ListFiles("/mnt/appname/My Backup"))
For i=0 To FileList.Size-1
File.Copy(File.DirInternal,FileList.Get(i),"/mnt/appname/My Backup",FileList.Get(i))
Next
Log(File.ListFiles("/mnt/Jonsap/IV Drips"))

For the first Log it is stating that the directory doesn't exist. Then on the File.Copy line I get an error because the directory is invalid. And yes, I confirmed there are many files in DirInternal. Any ideas?
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
You path is definitely wrong.
What is the device under the mount point?
It should be something like "/mnt/sdcard" (and then your app and directory)

I see, I was wondering what mnt was exactly. What I am actually trying to do is copy the files to a directory on internal memory. Is there a universal path for this?

Sent from my DROIDX
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I always use file.DirRootExternal for custom paths on the sdcard (internal memory)
file.DirDefaultExternal is your apps data path on the sdcard (internal memory).
Do a Log of both to see where they are pointed to.

/mnt is a directory on linux/android where you can see all storage devices mounted.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User

So this will work for devices that don't have any external storage?

Sent from my DROIDX
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Maybe Erel can confirm for us soon. Does DirDefaultExternal get deleted when the app is uninstalled?

Edit:
Well I just made an emulator with no SD card support, and DirRootExternal fails because it tries to write to /mnt/sdcard/.
Basically all I need is a fail-safe Internal directory that I can copy files to on any device. Help?
 
Last edited:
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
I would think that DirDefaultExternal would be removed because itn't it tied to your application directly?

Is there a way to see the contents of the dir from a pc or mac? Like I can on my windows phone?

I don't yet have a real device to check all this out. My samsung galaxy s2 is coming in the next few days.

If there's a way to independently look at a dir's contents you could install your app on your device, look that it's there. Do the backup then uninstall and look to see if it's still there.

Being a newbie to android I guess it's not as easy as that.

regards, Ricky
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Tested it on the emulator and it appears that the files in DirRootExternal are saved after an uninstall. Again problem lies with devices that do not have "external" storage (like this emulator I created with no SDcard support). I cannot copy files to DirRootExternal on this emulator.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Yes. It gets deleted.

So Erel can you help? I am looking for the directory path on internal memory that I can copy files to that won't get delete. This is for devices that don't have any "external" memory.
 
Upvote 0

gwapong

Member
Licensed User
Longtime User
Erel is there a sample code wherein i can backup my database from the device into the directory of my choice lets say for example d:\b4a\sample
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…