in a project, I would like to copy the sqlite db from the folder:
/res/raw
to the folder:
/data/data/{package_name}/databases/
like it said in the this link. And it doesn't make the copy on the destination folder. Here is my code: MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("Components onCreate","setContentView");
setContentView(R.layout.activity_main);
MySQLiteHelper n = new MySQLiteHelper(getApplicationContext());
try {
Uri url = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.myfile);
boolean temp = n.importDatabase(url.toString());
Log.i("Components onCreate",""+temp);
} catch (IOException e) {
e.printStackTrace();
}
MySQLiteHelper.java:
public boolean importDatabase(String dbPath) throws IOException {
// Close the SQLiteOpenHelper so it will commit the created empty
// database to internal storage.
close();
File newDb = new File(dbPath);
File oldDb = new File(DB_FILEPATH);
Log.i("ImportDatabase", "Database " + newDb.exists());
if (newDb.exists()) {
FileUtils.copyFile(new FileInputStream(newDb), new FileOutputStream(oldDb));
// Access the copied database so SQLiteHelper will cache it and mark
// it as created.
getWritableDatabase().close();
return true;
}
return false;
}
On my logcat i am gettin false all the time. Here it is:
I/ImportDatabase﹕ Database false
I don't know what I am making wrong? Any hints? Thanks.