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()
}
Android Studio project R can't find
Explain Fragment Life Cycle
Check List for Generate Signed APK Android
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to convert DP to Pixel and Pixel to Dp?
How do i load image from drawable folder in Jetpack Compose?
What are Android Versions available?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
Android FCM not receiving notifications when app is removed from background
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
How to get complete address from latitude and longitude?
How to get screen size (width,height) in Android?
How to check Android version?
How to start a new activity on button click
Key Points to remember while develop the Android Application.
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
What is ANR in android?
How to convert milli seconds to hours, minutes and seconds in Android?
What is NetworkOnMainThread Exception?
What is the difference between match_parent and fill_parent?
How to Generate signed apk with android studio
How to get a contact image using a phone number in android?
What are the notifications available in android?
How to add jar/library files as a dependency in Android studio gradle file
How to stop EditText focus at Activity startup in Android?
Hide/Disable soft keyboard on Activity launch: Android
How to validate email address in Android with Kotlin?
Invoke-customs are only supported starting with android 0 --min-api 26
How to avoid multiple button click at same time in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
What is Android?
How to copy database from assets folder in android using kotlin
How to get an image resource by it's name in android?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
What is Android Fragments?
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What are symmetric and asymmetric encryption in the way Android interacts with the server?
How to install/ uninstall apk by command line ADB
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent