I'm doing this right now and it's working..so I share my code..maybe this would help you.
File file = new File(Environment.getExternalStorageDirectory(), "my.db");
InputStream in = null;
OutputStream out = null;
try {
in = getAssets().open("my.db"); //.I'm in a service, so I don't need context
out = new FileOutputStream(file);
int count = 0;
byte[] buffer = new byte[1024*4];
while ((count = in.read(buffer)) != -1) {
out.write(buffer, 0, count);
out.flush();
}
} catch (IOException err) {
Log.e(TAG, err.getMessage(), err);
} finally {
if (in != null)
try { in.close(); }
catch (IOException ignore) { }
if (out != null)
try { out.close(); }
catch (IOException ignore) { }
}
Edit 1
Here the SQLiteOpenHelper
code
public class SchemaHelper extends SQLiteOpenHelper {
static final private String DATABASE_NAME = "my.db";
static final private int DATABASE_VERSION = 1;
private SchemaHelper( Context context ) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate( SQLiteDatabase db ) {
/* The database has 6 tables pre-populated */
/* This one is the only created at runtime */
/* and editable by the user */
ShoppingListTable.onCreate(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
/* The database has 6 tables pre-populated */
/* This one is the only created at runtime */
/* and editable by the user */
ShoppingListTable.onUpgrade(db, oldVersion, newVersion);
}
}
Edit 2
ShoppingListTable is an helper static class which define the column fields and the creation/upgrade. This is the only Table created at runtime, all the others are pre-created and pre-filled.
public class ShoppingListTable {
static final public String COLUMN_PRODUCT_ID = BaseColumns._ID;
static final public String COLUMN_PARSE_OBJECT_ID = "objectId";
static final public String COLUMN_LAST_UPDATE = "lastUpdate";
static final public String TABLE_NAME = "ShoppingList";
static
public void onCreate(SQLiteDatabase database) {
StringBuilder sql = new StringBuilder();
sql.append("CREATE TABLE ").append(TABLE_NAME).append(" (");
sql.append(COLUMN_PRODUCT_ID).append(" INTEGER PRIMARY KEY NOT NULL, ");
sql.append(COLUMN_PARSE_OBJECT_ID).append(" TEXT, ");
sql.append(COLUMN_LAST_UPDATE).append(" INTEGER DEFAULT -1, ");
sql.append(COLUMN_SYNCSTATE).append(" INTEGER DEFAULT 0 ");
sql.append(");");
database.execSQL(sql.toString());
}
static
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
Log.w( ShoppingListTable.class.getName(), "Upgrading database from version "
+ oldVersion + " to " + newVersion + ", which will destroy all old data" );
database.execSQL("DROP TABLE IF EXISTS " + ShoppingListTable.TABLE_NAME );
ShoppingListTable.onCreate(database);
}
}