We can copy database from assets folde by class CopyAssetDatabaseOpenHelper(private val context: Context) { companion object { private val DB_NAME = "dbName.db" fun openDatabase(): SQLiteDatabase { checkDB?.close() } val buffer = ByteArray(1024) currentDB.flush() }
}
val dbFile = context.getDatabasePath(DB_NAME)
if (!dbFile.exists()) {
try {
val checkDB = context.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE,null)
copyDatabase(dbFile)
} catch (e: IOException) {
throw RuntimeException("Error creating source database", e)
}
return SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READWRITE)
}
private fun copyDatabase(context:Context) {
val dbFile = context.getDatabasePath("logicaldb")
val assetdb = context.assets.open("logicaldb")
val currentDB = FileOutputStream(dbFile)
while (assetdb.read(buffer) > 0) {
currentDB.write(buffer)
Log.d("#DB", "Copying "+buffer.toString())
}
currentDB.close()
assetdb.close()
}
How to get complete address from latitude and longitude?
What is Application?
Open PDF in Google Drive with Intent in Android - RRutors
How to check Android version?
How To Set Text Color Programmatically Android TextView?
How to Get bitmap from drawable: Android
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is NetworkOnMainThread Exception?
How to Use Deprecated Handler() in Android - RRutors Guide
FCM Not Receiving Notifications in Android - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to convert milli seconds to hours, minutes and seconds in Android?
How to find Android Device UDID or unique ID?
How to Exit android app on back pressed?
Check List for Generate Signed APK Android
What is the Different Between val and var in Kotlin?
What is "shared preferences" in Android ?
How to copy database from assets folder in android using kotlin
What is ANR in android?
How to stop EditText focus at Activity startup in Android?
What is Android?
How to reduce APK package size?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Extract Date and Time from Long Type Variable - RRutors
How to get an image resource by it's name in android?
What are Android Versions available?
Invoke-customs are only supported starting with android 0 --min-api 26
How do I check in SQLite whether a table exists?
Fix Android Emulator Kill Error When Running Your App
How do I generate random numbers in Dart?
How to get screen size (width,height) in Android?
What is Android Fragments?
How do i load image from drawable folder in Jetpack Compose?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to save activity State in Android?
Fix Play Store Rejection Due to SMS Permission - RRutors
How to validate email address in Android with Kotlin?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Explain Fragment Life Cycle
What is ANR? How to avoid and resolve it?