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()
}
What is "shared preferences" in Android ?
What is Application?
Hide/Disable soft keyboard on Activity launch: Android
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to install/ uninstall apk by command line ADB
How to get a contact image using a phone number in android?
Check List for Generate Signed APK Android
How to convert milli seconds to hours, minutes and seconds in Android?
How to Get bitmap from drawable: Android
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to find Android Device UDID or unique ID?
Fix Android Emulator Kill Error When Running Your App
What is the Different Between val and var in Kotlin?
Invoke-customs are only supported starting with android 0 --min-api 26
What is Context?
How to convert DP to Pixel and Pixel to Dp?
Explain Fragment Life Cycle
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get complete address from latitude and longitude?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to check Android version?
Permission denied for window type 2010 in Marshmallow device
What are the notifications available in android?
How can i comment inside xml file in android studio?
How to avoid multiple button click at same time in android?
What happens next when the device switches between portrait and landscape?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What is ANR? How to avoid and resolve it?
How to get screen size (width,height) in Android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How do I check in SQLite whether a table exists?
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Android Fragments?
FCM Not Receiving Notifications in Android - RRutors
How to Generate signed apk with android studio
Android Studio project R can't find
How do i load image from drawable folder in Jetpack Compose?
How to stop EditText focus at Activity startup in Android?
How do I generate random numbers in Dart?
How to Use Deprecated Handler() in Android - RRutors Guide