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 ?
How to start a new activity on button click
Open PDF in Google Drive with Intent in Android - RRutors
How To Set Text Color Programmatically Android TextView?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Key Points to remember while develop the Android Application.
How to get an image resource by it's name in android?
What is the Different Between val and var in Kotlin?
Check List for Generate Signed APK Android
How do I generate random numbers in Dart?
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Android Fragments?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to convert DP to Pixel and Pixel to Dp?
How to save activity State in Android?
How to Use Deprecated Handler() in Android - RRutors Guide
What happens next when the device switches between portrait and landscape?
What is Application?
Fix Android Emulator Kill Error When Running Your App
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
What are the notifications available in android?
How do i load image from drawable folder in Jetpack Compose?
How do I check in SQLite whether a table exists?
How to install/ uninstall apk by command line ADB
How to find Android Device UDID or unique ID?
How to avoid multiple button click at same time in android?
How to get a contact image using a phone number in android?
Set Activity to Fullscreen Mode in Android - RRutors
How to validate email address in Android with Kotlin?
Fix Play Store Rejection Due to SMS Permission - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How to reduce APK package size?
What are Android Versions available?
How to Generate signed apk with android studio
How to check Android version?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to get screen size (width,height) in Android?
What is NetworkOnMainThread Exception?
What is the difference between match_parent and fill_parent?
What is ANR in android?