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()
}
Permission denied for window type 2010 in Marshmallow device
How to Exit android app on back pressed?
How To Set Text Color Programmatically Android TextView?
How to save activity State in Android?
How to get screen size (width,height) in Android?
What is "shared preferences" in Android ?
Android Studio project R can't find
How can i comment inside xml file in android studio?
What is ANR in android?
How to Use Deprecated Handler() in Android - RRutors Guide
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Fix Play Store Rejection Due to SMS Permission - RRutors
Extract Date and Time from Long Type Variable - RRutors
Explain Fragment Life Cycle
How to reduce APK package size?
How to check Android version?
Invoke-customs are only supported starting with android 0 --min-api 26
FCM Not Receiving Notifications in Android - RRutors
How to convert milli seconds to hours, minutes and seconds in Android?
Open PDF in Google Drive with Intent in Android - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
What are the notifications available in android?
How do I check in SQLite whether a table exists?
How to Get bitmap from drawable: Android
How to install/ uninstall apk by command line ADB
What is Application?
Check List for Generate Signed APK Android
How to stop EditText focus at Activity startup in Android?
How to convert DP to Pixel and Pixel to Dp?
What is Android?
How to get a contact image using a phone number in android?
What is the difference between match_parent and fill_parent?
What are Android Versions available?
What is Context?
What is NetworkOnMainThread Exception?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Key Points to remember while develop the Android Application.
Fix Android Emulator Kill Error When Running Your App