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 convert milli seconds to hours, minutes and seconds in Android?
How to start a new activity on button click
Google play store rejected my app due to SMS permission I removed SMS permission from the manifes
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How do I generate random numbers in Dart?
How to Generate signed apk with android studio
How to validate email address in Android with Kotlin?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is ANR? How to avoid and resolve it?
What is "shared preferences" in Android ?
Check List for Generate Signed APK Android
What are Android Versions available?
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How to install/ uninstall apk by command line ADB
Error: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path
How to extract date and time from Long type variable in Kotlin on Android "
What is Android Fragments?
How to reduce APK package size?
How to avoid multiple button click at same time in android?
How to get screen size (width,height) in Android?
What is Context?
Android Studio project R can't find
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How to save activity State in Android?
How to convert DP to Pixel and Pixel to Dp?
Explain Fragment Life Cycle
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to Get bitmap from drawable: Android
What is NetworkOnMainThread Exception?
Key Points to remember while develop the Android Application.
How to get complete address from latitude and longitude?
How do I check in SQLite whether a table exists?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How can i comment inside xml file in android studio?
What is Intent? What is the difference between an implicit intent and an explicit intent?
What happens next when the device switches between portrait and landscape?
How to get an image resource by it's name in android?