Setting up a database on an android device (SOLVED)

Hello !
I need to create a folder on the android device on which the application is installed to put the database’s files. I am using flatDB so I need to set a path to a folder when I initialize the database, example :

local flatdb = require 'main.db.flatdb'
db = flatdb('C:/User/database')

It works perfectly on a my PC, but if I want to install it on an android device I need to set a path to a folder on the device’s internal storage. I tried many different path like /data/data/package.name or storage/emulated/0 and nothing works.
Do you know anything about it ?

Yes, don’t hardcode the path. Use sys.get_save_file(“myappname”, “database”) to get a full path to a file named “database” in a folder that you have permission to read and write to.

I wanted to do that but how do I get the path of the folder without /database at the end ?

Well, I suppose passing in an empty filename would work:

local path = sys.get_save_file(“myappname”, “”)
2 Likes

How did I missed it, this is so simlpe and elegant ! Works like a charm !
Thank you so much for your quick answer !

1 Like