0

I have an sql file (products.db) that I want to populate using SqliteBrowser. Then, I want my app to just read this file and show results based on user's search results. I dont want my app to create any sql files. In which folder of my computer's project folder (please share exact path) should I put the file so it can be installed with the app, and from where do I have to read the file when the app executes?

I hope I am making sense. Thank you!

Lambros
  • 151
  • 2
  • 14

1 Answers1

2

In which folder of my computer's project folder (please share exact path)

We cannot tell the path on your computer, as we cannot see your computer from here.

Assuming that you are using Android Studio, and have a traditional Android Studio project, put the database in app/src/main/assets/ off of your project root directory.

from where do I have to read the file when the app executes?

Use SQLiteAssetHelper to copy the database file from your app's assets into a local file on the device that you can use.

See this project for a sample app implementing the above instructions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • thx for answering. I did put it there but it does not get copied over. From my understanding it should be copied at the tablet in the folder "data/data/PACKAGE_NAME/databases. All I can see though in the tablet's file explorer in there is the cache folder and "lib" – Lambros Oct 17 '15 at 18:40
  • 1
    @Lambros: "From my understanding it should be copied at the tablet in the folder "data/data/PACKAGE_NAME/databases" -- only if you are using `SQLiteAssetHelper` or are otherwise copying the asset to internal storage. "All I can see though in the tablet's file explorer" -- you have no access to that directory by any tools except your own app and `adb shell`, and even with `adb` you need to use `run-as`. – CommonsWare Oct 17 '15 at 18:42
  • That was helpfull. thx! I wanter to know how can I see this folder in my tablet? I added the SQLAssetHelper and configured it but the directory does not have the file yet. I am asking because I know you can see it by exploring a virtual device on Android Studio. Can you see it on an actual device? – Lambros Oct 17 '15 at 18:55
  • 1
    @Lambros: "Can you see it on an actual device?" -- not directly, but you can copy it somewhere that you can see: http://stackoverflow.com/questions/6928849/debugging-sqlite-database-on-the-device/8434477#8434477 – CommonsWare Oct 17 '15 at 19:04