0

i created my first app and I would ship it with a local database that contains about 600 entries. I tried to hard-code this data in my class but i think it is not a good idea. So is it possible to copy a database to phone on first start of an application?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
smartmouse
  • 13,912
  • 34
  • 100
  • 166

3 Answers3

1

Store the file in assests folder or in the xml format in res folder.During start up you can copy to the database.

Meher
  • 2,545
  • 3
  • 26
  • 53
1

Rather than hardcoding.You can place that .db file in the assests folder of your application's project.Then by using simple File IO of java.You can copy the file from assests and place it in the respective folder from where you can have access to it in your application.


See this link

Community
  • 1
  • 1
nobalG
  • 4,544
  • 3
  • 34
  • 72
0

It mostly depends on your application type, and the sensitivity of the data, some of the possibilities I can think of:

  • Adding a raw SQL text file with all the values to your project. Then you check every time in Application.onCreate() if the database exists. If not, you run the import job which runs the SQL on the newly created database.

  • Same as the first one, but you download the SQL file over https, ensuring that decompiling the application does not leak the information. You need to ensure the user has an internet connection though.

  • If you prefer using database dumps, you can also import (and export) SQLite dumps. Then you could use the methods described here to set it up in your app. I would not recommend it, because fixing small things is done easier in SQL than in dumps.

Community
  • 1
  • 1
Daniel Zolnai
  • 16,487
  • 7
  • 59
  • 71