regulaforensics / DocumentReader-Android

Android Framework for reading and validation of identification documents
64 stars 26 forks source link

Every time downloading database happens on app launch #26

Closed kishorejethava closed 3 years ago

kishorejethava commented 3 years ago

Use-case: I want just download database on launching app and want to initialisation reader process later on. Issue: Every time downloads database on relaunch app, after removing reading licence and initialisation reader code from sample code.

How to reproduce:

  1. remove reading licence file code, ex: resources.openRawResource(R.raw.regula)
  2. remove initializeReader code, ex:initializeReader
  3. run fresh app with below download code
  4. download will happen first time
  5. download will happen second time and so on (Issue)

here is sample code

val initDialog = showDialog("Initializing")
            //Reading the license from raw resource file
            try {
                //preparing database files, it will be downloaded from network only one time and stored on user device
                DocumentReader.Instance().prepareDatabase(
                    this@MainActivity,
                    "Full",
                    object : IDocumentReaderPrepareCompletion {
                        override fun onPrepareProgressChanged(progress: Int) {
                            initDialog.setTitle("Downloading database: $progress%")
                        }
                        override fun onPrepareCompleted(status: Boolean, error: Throwable?) {
                            initDialog.dismiss()
                        }
                    })
            } catch (ex: Exception) {
                ex.printStackTrace()
            }
vyakimchik commented 3 years ago

Hi @kishorejethava,

Thanks for your detailed report!

Unfortunately, yes, it works at the moment as you described. Could you please describe your use-case of why you want to run the initialization process later?

kishorejethava commented 3 years ago

Because It's taking long time to download and initialization so we separated both, and does downloading setup at the time of first launch of app.

vyakimchik commented 3 years ago

prepareDatabase will download the database only once. It will be downloaded next time when it's removed from the app or it's incompatible with the SDK. So, even if you will invoke the prepareDatabase each time when the app starts and it meets the conditions that I described, it won't be downloaded each time. Therefore, you can run the initialization process right after the prepareDatabase finishes its work.

vyakimchik commented 3 years ago

Also, you can add the database manually to the project if you don't want to download it via the Internet using the prepareDatabase / runAutoUpdate: https://docs.regulaforensics.com/android/database#adding-database-manually.

kishorejethava commented 3 years ago

We are checking that Database exist or not by following function and its working fine.

private fun isDatabaseExist(): Boolean {
        val storagePath = File(getExternalFilesDir(null as String?), "Regula/db.dat")
        val applicationPath = File(filesDir, "Regula/db.dat")
        val atApplicationPath = applicationPath.exists()
        val atStoragePath = storagePath.exists()
        Timber.tag(SplashActivity::class.java.simpleName).d("atApplicationPath:${atApplicationPath} | atStoragePath:${atStoragePath}")
        return if (atApplicationPath) {
            true
        } else atStoragePath
    }