Where is the right place to store your app's settings?

priitp

Member
Licensed User
Longtime User
Currently I do save some settings and temp files at "File.DirDefaultExternal".
But for phones without SD card the solution doesn't work.
Also checked "Can isntall to external storage".

I wonder if there is a universal path available what phone OS itself will direct to internal memory or SD depending on available recources.

I know the trick to greate virtual SD card but looks weird to mess around so much with so trivial problem.

Priit
 

Mahares

Expert
Licensed User
Longtime User
I could not even find the folder. Where do you recommend I save my files and databases on this particular phone with no SD card. Or, should I get an SD card for it and store the files on the SD card. I wasted a full 8 hours. It is very frustrating when the answer is not obvious.
Thanks a lot for a follow-up.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have an application that has an SQLite database that is constantly changing and another application that has a text file with an ID that the first one must access. FileDirInternal does not refer to the same folder since both apps had different package names. I must have my databases and files where they can be accessed and viewed, not just simply inserted to. If you do not have an alternative to storing files for phones without SD card and being able to access them, will I have to equip it with an SD card for this to work? I cannot find the proper smily because the one I want to use is bleeding.
Bless your Soul
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I think you will have to read the page I mentioned very carefully and decide what is good for yourself.

Using the External Storage

Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

Caution: External files can disappear if the user mounts the external storage on a computer or removes the media, and there's no security enforced upon files you save to the external storage. All applications can read and write files placed on the external storage and the user can remove them.

The ideal way for apps to share data would be to use Content Providers. I dont understand much about them however.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
This should be pretty easy to take care of. On one of the devices I use the default root directory of the Internal memory is /mnt/media. So, if I wanted to share data between two apps on this device I would create a folder like this:

B4X:
Dummy = File.DirInternal    'This is needed because it gives the Android OS permission to read and write to memory
'but it is not used by your code, it's just to set permission in the OS
File.MakeDir("/mnt/media","mydirname/appname")
'Then access it
filename = "/" & "myfile.dat"
ans = File.ReadList("/mnt/media", "mydirname/appname" & filename)
'Any app can access this path
'You can clean this up by doing it like this
mypath = "/mnt/media/mydirname/appname/"
filename = "myfile.dat"
ans = File.ReadList("", mypath & filename)

I use this in many apps I have written and no SDCard is needed. The only down side is that the user can access this via usb and could erase the files. These files also will stay on the device even if the app is un-installed. Hope this helps.

Margret
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thank you very much TDS and Margret for your suggestions. You are amazing people. After spending a full 8 unnecessary hours trying to figure out why I could not view data or folders for a non rooted phone, I decided to buy an SD card which I just installed and the application works fine. All the programming I have done so far with B4A was using an SD card in a phone. I did not realize the magnitude of the shortfall of not using a card. An FAQ section in the forum could have probably saved me a lot of time.
 
Upvote 0

Osi

Member
Licensed User
Longtime User
>I wonder a bit as this is so common problem that may be it is wize to have
>it built in to Basic4android as a readonly string variable.

No because some developers will use only one specific folder and two, not predefining it lets you choose your own, meaningful name.

Perhaps I should of clarified? I was only able to download into one of the directories and not the other two.
 
Upvote 0

rfresh

Well-Known Member
Licensed User
Longtime User
Thank you very much TDS and Margret for your suggestions. You are amazing people. After spending a full 8 unnecessary hours trying to figure out why I could not view data or folders for a non rooted phone, I decided to buy an SD card which I just installed and the application works fine. All the programming I have done so far with B4A was using an SD card in a phone. I did not realize the magnitude of the shortfall of not using a card. An FAQ section in the forum could have probably saved me a lot of time.

I think this is a short coming with how Google has designed their File System. File and folder locations is needlessly complex, what with hidden files and folders, Internal locations, External locations, SD Card or no SD Card, it's a real mess.

And as for exposing files to users, if users choose to delete files they have no knowledge about, then that's their responsibility. This is absolutely, repeat, absolutely no different than developing an app for a windows or a mac machine. If a user wants to go into their windows folder and start deleting files they have no knowledge of, then they take responsibility for messing up their OS. You have the same issues here. Google has made their Android file system needlessly complicated for us developers.
 
Upvote 0
Top