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?
Fix Play Store Rejection Due to SMS Permission - RRutors
What is Context?
How to avoid multiple button click at same time in android?
What happens next when the device switches between portrait and landscape?
What is Android?
What is ANR in android?
How to get an image resource by it's name in android?
Check List for Generate Signed APK Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get screen size (width,height) in Android?
Set Activity to Fullscreen Mode in Android - RRutors
How to find Android Device UDID or unique ID?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Decompile APK Files: How to Get Source Code - RRutors Guide
How to install/ uninstall apk by command line ADB
What is the difference between match_parent and fill_parent?
Invoke-customs are only supported starting with android 0 --min-api 26
How to Get bitmap from drawable: Android
How to convert milli seconds to hours, minutes and seconds in Android?
What is the Different Between val and var in Kotlin?
How do I check in SQLite whether a table exists?
How to save activity State in Android?
What are the notifications available in android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is NetworkOnMainThread Exception?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Hide/Disable soft keyboard on Activity launch: Android
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to validate email address in Android with Kotlin?
How to check Android version?
Android Studio project R can't find
How can i comment inside xml file in android studio?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Extract Date and Time from Long Type Variable - RRutors
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to Exit android app on back pressed?
Fix Android Emulator Kill Error When Running Your App
What is ANR? How to avoid and resolve it?
How to Generate signed apk with android studio