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 bitmap from drawable: Android
What is Android?
How to get complete address from latitude and longitude?
How to copy database from assets folder in android using kotlin
What is ANR? How to avoid and resolve it?
What are Android Versions available?
How to stop EditText focus at Activity startup in Android?
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What is Android Fragments?
How to install/ uninstall apk by command line ADB
What is ANR in android?
Android FCM not receiving notifications when app is removed from background
How to get a contact image using a phone number in android?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
Android Studio project R can't find
How to get an image resource by it's name in android?
How to avoid multiple button click at same time in android?
Check List for Generate Signed APK Android
Permission denied for window type 2010 in Marshmallow device
How to check Android version?
How To Set Text Color Programmatically Android TextView?
What is the Different Between val and var in Kotlin?
How to Generate signed apk with android studio
How to start a new activity on button click
How to convert DP to Pixel and Pixel to Dp?
Invoke-customs are only supported starting with android 0 --min-api 26
What is the difference between match_parent and fill_parent?
How do I generate random numbers in Dart?
What are symmetric and asymmetric encryption in the way Android interacts with the server?
How to Exit android app on back pressed?
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to reduce APK package size?
What is Application?
How to convert milli seconds to hours, minutes and seconds in Android?
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
Hide/Disable soft keyboard on Activity launch: Android
How do i load image from drawable folder in Jetpack Compose?
Explain Fragment Life Cycle
What is Intent? What is the difference between an implicit intent and an explicit intent?