Android Question Doanload, save and show image in ImageView

Ariston

Member
Licensed User
Longtime User
Hi everybody.

Until Android 10.0 I managed to download, save and display images in ImageView with this code:

B4X:
Dim J As HttpJob
j.Initialize("", Me)
j.Download("http://www." & cUrl.Trim & "/images/produtos/PRD" & cImg.SubString2(nlen, 13+nlen) & ".jpg")
Wait For (j) JobDone(jo As HttpJob)
If j.Success Then
    Try
        imgProd.Bitmap = j.GetBitmap
        lErr = False
    Catch
        ToastMessageShow("Erro 03: " & LastException.Message, True)
        Log(LastException.Message)
    End Try
End If

After the last update it stoped working.

Any better tip on how to donwload, save and display photos?
 

drgottjr

Expert
Licensed User
Longtime User
have you set up cleartext in your manifest. search for "cleartext" in the little box above. http is not allowed by default. only https. you have to specifically allow http
 
Upvote 0

Ariston

Member
Licensed User
Longtime User
I added these lines to manifest, but with no success.

B4X:
' 28 - Non-ssl (non-https) communication is not permitted by default.
' It can be enabled in B4A v9+ by adding this line to the manifest editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)
SetApplicationAttribute(android:usesCleartextTraffic, "true")

So I stopped using http:// (changed to https://).
Without try/catch I got this error:



How can I fix it?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Are you sure that the URL is correct and should work with https? Check if the url http or https. Just in a browser.
 
Upvote 0

Ariston

Member
Licensed User
Longtime User
Yes. It is correct.
I have just managed to download and save a picture using FileProvider.
I also managed to share it via Whatsapp (just to test).
I only could not make the image show in ImageView, but I believe I am getting close.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…