private fun downloadfile( filUrl: String, filePath: String, completion: (response: String) -> Unit ) { binding.progressBar.max = 100 binding.progressBar.setProgress(0) binding.progressTextView.setText("0") val storage = FirebaseStorage.getInstance() val storageRef = storage.getReferenceFromUrl(filUrl) val localFile = File(filePath) storageRef.getFile(localFile) .addOnProgressListener { Log.e(TAG, "downloadfile: " + it.bytesTransferred + "/" + it.totalByteCount) if (it.totalByteCount.toInt() != -1) { val progress: Double = 100.0 * it.bytesTransferred / it.totalByteCount binding.progressBar.setProgress(progress.toInt()) binding.progressTextView.setText(progress.toInt().toString()) } } .addOnSuccessListener(object : OnSuccessListener<FileDownloadTask.TaskSnapshot?> { override fun onSuccess(taskSnapshot: FileDownloadTask.TaskSnapshot?) { Log.e( TAG, "downloadfile:onSuccess: ;local tem file created created $localFile" ) completion("1") } }).addOnFailureListener(object : OnFailureListener { override fun onFailure(@NonNull exception: java.lang.Exception) { Log.e( TAG, "downloadfile:onFailure: ;local tem file not created created $exception" ) completion("downloadfile:onFailure: ;local tem file not created created $exception") } }) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter