Android Question json & images

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
within my REST API response I have this json object (it's an image within a drupal article):

B4X:
 "field_media_image": [
        {
            "target_id": 10,
            "target_type": "media",
            "target_uuid": "6e4aa020-0713-4da4-92d7-cc4a9c70bc35",
            "url": "/drupal/en/media/10/edit"
        }
    ]

My target is to display the image within the android app (in my case I have to show a list of articles with all the related images and titles).
Which is the correct code snippet (using OKHttpUtils2 framework) to do this at runtime without save the image within the local android db in order to have only one centralized data source on drupal db ?

Thank you in advance for your help :)
Luca.
 

drgottjr

Expert
Licensed User
Longtime User
downloading an image using okhttputils2 is easy enough:
B4X:
        dim somebitmap as bitmap
        somebitmap.Initialize2(Job.GetInputStream)
       Job.Release

       dim someimageview as imageview
       initialize
       activity.addview
       someimageview.bitmap = somebitmap   (maybe resize, whatever)

no need to save it locally; just assign it to an imageview.
the request to download is a normal httpjob.download( url_to_image ). presumably, no way to know the image's url until you've handled the json request. so you have to go back for it. unclear to me if the various elements of that json response are enough for you to grab the image. if you're in charge of the response, you might want to make sure whatever you need to download the image is present in the response.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
downloading an image using okhttputils2 is easy enough:
B4X:
        dim somebitmap as bitmap
        somebitmap.Initialize2(Job.GetInputStream)
       Job.Release

       dim someimageview as imageview
       initialize
       activity.addview
       someimageview.bitmap = somebitmap   (maybe resize, whatever)

no need to save it locally; just assign it to an imageview.
the request to download is a normal httpjob.download( url_to_image ). presumably, no way to know the image's url until you've handled the json request. so you have to go back for it. unclear to me if the various elements of that json response are enough for you to grab the image. if you're in charge of the response, you might want to make sure whatever you need to download the image is present in the response.

Thanks @drgottjr! I'll try :)
 
Upvote 0
Top