• How to add progress bar to this fun?

    From Jakub@[email protected] to comp.mobile.android on Mon Jun 1 15:00:15 2026
    From Newsgroup: comp.mobile.android


    How to add progress bar to this fun to show procent loading?

    fun doHttpsConnectUrlGetImage02(aimageView: ImageView?, aurl: String) {

    var httpsURLConnection : HttpsURLConnection
    val zimageView = aimageView.toString()
    Log.i("ppp", "aurl -> " + aurl + " zimageview -> " +zimageView)
    Log.i("ppp", "fun doHttpsConnectUrlGetImage02(aimageView:
    ImageView, aurl: String ) {")

    val zurl = "$aurl?t=${System.currentTimeMillis()}"

    var zbitmap04 : Bitmap? = null
    var ztimer = 0

    CoroutineScope(Dispatchers.IO).launch {
    try {
    val url = URL(zurl)
    httpsURLConnection = url.openConnection() as HttpsURLConnection
    //
    httpsURLConnection.setRequestProperty("Cache-Control", "no-cache")
    // httpsURLConnection.defaultUseCaches = false
    // httpsURLConnection.setUseCaches(false)

    httpsURLConnection.doInput
    httpsURLConnection.connect()

    val inputStream = httpsURLConnection.getInputStream()

    ztimer++

    Log.i("ppp", "ztimer -> " + ztimer)

    zbitmap04 = BitmapFactory.decodeStream((inputStream))

    httpsURLConnection.disconnect()
    } catch ( _ : Exception ) {
    }

    // Update UI for download is successful
    withContext(Dispatchers.Main) {
    aimageView?.setImageBitmap(zbitmap04)
    }
    }
    }
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Arno Welzel@[email protected] to comp.mobile.android on Sun Jun 7 10:23:37 2026
    From Newsgroup: comp.mobile.android

    Jakub, 2026-06-01 15:00:


    How to add progress bar to this fun to show procent loading?

    [...]

    val inputStream = httpsURLConnection.getInputStream()

    ztimer++

    Log.i("ppp", "ztimer -> " + ztimer)

    zbitmap04 = BitmapFactory.decodeStream((inputStream))

    Do not use BitmapFactory.decodeStream() but download the stream
    "manually" and then decode the bitmap after downloading. However this
    still leaves a problem unsolved: you don't know how many bytes will be
    sent on the stream - but this information would be required to determine
    the progress.

    So in addition you need to analyse the HTTP response headers for the URL
    to see if there is any Content-length field present.
    --
    Arno Welzel
    https://arnowelzel.de
    --- Synchronet 3.22a-Linux NewsLink 1.2