Skip to content

Instantly share code, notes, and snippets.

@nguyenlinhnttu
Last active January 2, 2018 06:28
Show Gist options
  • Save nguyenlinhnttu/af25a265968af7372afc379a112c6a3c to your computer and use it in GitHub Desktop.
Save nguyenlinhnttu/af25a265968af7372afc379a112c6a3c to your computer and use it in GitHub Desktop.
SQLite Kotlin
class SqlHelper(var mContext: Context) {
val DB_NAME: String = "essays_eng.db"
fun openDataBase(): SQLiteDatabase {
val dbFile : File = mContext.getDatabasePath(DB_NAME)
if (!dbFile.exists()) {
val dir = dbFile.parentFile
dir.mkdirs()
mContext.assets.open(DB_NAME).use { input -> dbFile.outputStream().buffered().use { output ->
input.copyTo(output, 10240 )
}
}
}
return SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READWRITE)
}
}
@nguyenlinhnttu
Copy link
Author

Should use FIRST START APP. IF database bug size please set delay time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment