1,234
edits
Changes
→Test data
* Quit
<pre>.quit</pre>
== Using a pre-built DB file ==
If you want your app to come with some pre-built data in the database then it's probably easiest to follow the example above to create the file, add it to your resources, and copy it into the correct place the first time your app starts. For example:
<pre>try
{
String destPath = "/data/data/" + context.getPackageName() + "/databases/";
File destPathFile = new File(destPath);
if (!destPathFile.exists())
destPathFile.mkdirs();
File destFile = new File(destPath + DB_FILE_NAME);
if (!destFile.exists())
{
Log.d(TAG, "First run, copying default database");
copyFile(context.getAssets().open(DB_FILE_NAME),
new FileOutputStream(destPath + "/" + DB_FILE_NAME));
}
}
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
dbOpenHelper = new DatabaseOpenHelper(context);</pre>
Make sure this code runs when your app starts up and don't forget to put your db file in the assets folder.