I have written this code snippet to download image files from firebase storage to local storage.
contentResolver.openOutputStream(uri)?.use { ops -> // *
Firebase.storage.getReferenceFromUrl(model.mediaUrl).stream.await().stream.use { ips ->
val buffer = ByteArray(1024)
while (true) {
val bytes = ips.read(buffer) // *
if (bytes == -1)
break
ops.write(buffer, 0, bytes) // *
}
}
}
In the marked lines, android studio is giving me Inappropriate blocking method call
warning, highlighting openOutputStream(), read() and write() functions. I have ran the code few times and it has worked properly. This entire code snippet is inside a suspend function, called from an IO CoroutineScope.
Someone please tell me the actual cause and solutions for this warning.
Edit This code is called in the following context.
fun someFunc() {
lifecycleScope.launch(IO) {
val uri = getUri(model)
...
}
...
}
...
suspend fun getUri(model: Message): Uri {
... // Retrive the image file using mediastore.
if ( imageNotFound ) return downloadImage(model)
else return foundUri
}
suspend fun downloadImage(model: Message): Uri {
... // Create contentvalues for new image.
val uri = contentResolver.insert(collectionUri, values)!!
// Above mentioned code snippet is here.
return uri
}