How to show progress of Model downloaded from ML Kit

892 Views Asked by At

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()
        }
}
1

There are 1 best solutions below

2
On BEST ANSWER

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