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()
}
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
FCM Not Receiving Notifications in Android - RRutors
What is NetworkOnMainThread Exception?
How to get a contact image using a phone number in android?
What happens next when the device switches between portrait and landscape?
How to reduce APK package size?
What is ANR? How to avoid and resolve it?
Set Activity to Fullscreen Mode in Android - RRutors
How do i load image from drawable folder in Jetpack Compose?
How to get an image resource by it's name in android?
Open PDF in Google Drive with Intent in Android - RRutors
What is Android Fragments?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to Use Deprecated Handler() in Android - RRutors Guide
How to get complete address from latitude and longitude?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to install/ uninstall apk by command line ADB
How can i comment inside xml file in android studio?
What is ANR in android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How To Set Text Color Programmatically Android TextView?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What are Android Versions available?
How to save activity State in Android?
What is Context?
What is Android?
Permission denied for window type 2010 in Marshmallow device
Android Studio project R can't find
Add Jar/Library Files as Dependency in Android Studio
Invoke-customs are only supported starting with android 0 --min-api 26
How to convert DP to Pixel and Pixel to Dp?
What is the difference between match_parent and fill_parent?
How to get screen size (width,height) in Android?
How to Get bitmap from drawable: Android
Key Points to remember while develop the Android Application.
Hide/Disable soft keyboard on Activity launch: Android
Fix Android Emulator Kill Error When Running Your App
What is Application?