Android Question File.DirInternal & File.DirDefaultExternal

aaronk

Well-Known Member
Licensed User
Longtime User
HI,

I am using a SQLite database in my app.

When I create it, where would be the best place to save it on the device ?

I have read that the file can be saved in File.DirDefaultExternal and also read it can be put in File.DirInternal.

I want to be able to keep this file after a app update or a Android OS update.

From what I can see the difference between the 2 is:
File.DirInternal stores it in a location where the user can't browse to and no other app can access this file.
File.DirDefaultExternal the user can view this file if they was to browse for this file.

Other than that, is that the only difference ?

Which is the best location to save this file ?
 

Mahares

Expert
Licensed User
Longtime User
I want to be able to keep this file after a app update or a Android OS update.

The other folder which you did not mention is: File.DirRootExternal.
File.DirRootExternal: It is a portion of the internal device memory referred to as the secondary storage. It is not the REMOVAL SD card. When you update apk, or OS or UNinstall the app, the database will still be there. If you are not concerned about someone manually deleting it, then it is an option. It is always very easy to locate via file manager. Other apps can access it.
File.DirInternal: if you uninstall app, you will lose the database. No other application can access it either. If you update OS or apk, you will be OK.
File.DirDefaultExternal: If you uninstall the app the database is lost. if you update OS or apk, you do not lose the database. Other apps can also access it.

The safest might be: DirDefaultExternal if you want to enforce Runtime permission. The following link gives you additional details:
https://b4x.com/android/forum/threads/file-properties-and-actual-folders.72757/
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Note that you should avoid using File.DirDefaultExternal
Shouldn't you be referring to File.DirRootExternal in your statement as the one you should avoid. When I use RuntTmePermission (rp.GetAllSafeDirsExterna), most generally, the first one that pops up is File.DirDefaultExternal. Can you give a case where it is not so?
 
Upvote 0
Top