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 Exit android app on back pressed?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How to reduce APK package size?
What is Android Fragments?
Decompile APK Files: How to Get Source Code - RRutors Guide
What are Android Versions available?
How to start a new activity on button click
How to Get bitmap from drawable: Android
How to Use Deprecated Handler() in Android - RRutors Guide
How to save activity State in Android?
What are the notifications available in android?
How to stop EditText focus at Activity startup in Android?
Key Points to remember while develop the Android Application.
What happens next when the device switches between portrait and landscape?
What is the difference between match_parent and fill_parent?
Open PDF in Google Drive with Intent in Android - RRutors
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to validate email address in Android with Kotlin?
What is Android?
How do I generate random numbers in Dart?
How To Set Text Color Programmatically Android TextView?
How to copy database from assets folder in android using kotlin
What is Context?
Explain Fragment Life Cycle
Invoke-customs are only supported starting with android 0 --min-api 26
What is NetworkOnMainThread Exception?
How to convert milli seconds to hours, minutes and seconds in Android?
How to convert DP to Pixel and Pixel to Dp?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is Application?
How to get a contact image using a phone number in android?
FCM Not Receiving Notifications in Android - RRutors
How to get complete address from latitude and longitude?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Fix Play Store Rejection Due to SMS Permission - RRutors
Fix Android Emulator Kill Error When Running Your App
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Android Studio project R can't find