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 a contact image using a phone number in android?
What is the difference between match_parent and fill_parent?
Hide/Disable soft keyboard on Activity launch: Android
What is Context?
How to Generate signed apk with android studio
What is Application?
Add Jar/Library Files as Dependency in Android Studio
What is NetworkOnMainThread Exception?
What is Android Fragments?
Fix Play Store Rejection Due to SMS Permission - RRutors
What is "shared preferences" in Android ?
Check List for Generate Signed APK Android
Decompile APK Files: How to Get Source Code - RRutors Guide
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to validate email address in Android with Kotlin?
How to avoid multiple button click at same time in android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is ANR in android?
Invoke-customs are only supported starting with android 0 --min-api 26
What are Android Versions available?
What happens next when the device switches between portrait and landscape?
How To Set Text Color Programmatically Android TextView?
FCM Not Receiving Notifications in Android - RRutors
Fix Android Emulator Kill Error When Running Your App
What is the Different Between val and var in Kotlin?
How to convert DP to Pixel and Pixel to Dp?
Extract Date and Time from Long Type Variable - RRutors
How do i load image from drawable folder in Jetpack Compose?
How do I check in SQLite whether a table exists?
What is ANR? How to avoid and resolve it?
How to reduce APK package size?
How to Exit android app on back pressed?
How to get an image resource by it's name in android?
How to convert milli seconds to hours, minutes and seconds in Android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What is Android?
How to stop EditText focus at Activity startup in Android?
How to check Android version?
Explain Fragment Life Cycle