How to show progress of Model downloaded from ML Kit

Issue

I’m using google digital ink for handwriting recognition. The models that need to get downloaded once are of 20MB size and the download requires some time. Is there any way to show the progress of the download using a progressbar?

My code is as follows:

fun download(context: Context) {
    var modelIdentifier: DigitalInkRecognitionModelIdentifier? = null
    try {
        modelIdentifier =
            DigitalInkRecognitionModelIdentifier.fromLanguageTag(lang)
    } catch (e: MlKitException) {
        // language tag failed to parse, handle error.
    }

    model = DigitalInkRecognitionModel.builder(modelIdentifier!!).build()

    val remoteModelManager = RemoteModelManager.getInstance()
    remoteModelManager.download(model, DownloadConditions.Builder().build())
        .addOnSuccessListener {
            Log.i("StrokeManager", "Model downloaded")
            Toast.makeText(context, "Model Downloaded", Toast.LENGTH_SHORT).show()

        }
        .addOnFailureListener { e: Exception ->
            Log.e("StrokeManager", "Error while downloading a model: $e")
            Toast.makeText(context, "Model Download Failed", Toast.LENGTH_SHORT).show()
        }
}

Solution

At this moment, the download API doesn’t report the exact downloading progress, e.g. 10%, 20%, 50%…
If we see more interests in it, we would consider adding such a support.

By the way, here is the same question asked in ML Kit github repo: https://github.com/googlesamples/mlkit/issues/165

Answered By – Steven

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published