Search code examples
androidpublish-subscribepubnub

managing pubnub image subscriptions


I am implementing a chat application with image sending feature using pubnub, I am able to publish the images. But while subscribing i am receiving the image link instead of the actual image . I get the message as a JSON object as ''' {"nameValuePairs":{"imageurl":"example.com"}}

''' . How do i use it to put it into an Imageview. Here is my code (The publish handler) ''' var image = JSONObject() as JSONObject image.put("imageurl","example.com")

''' The message recieved in the subscribe handler is a json object and not the image . Why isn't pubnub catching my image from the external server.


Solution

  • It's probably easiest to use a library called Glide. This will manage the downloading and scaling of the image for you. Follow the setup instructions and then simply after receiving the image url use the example code like this:

    Glide
        .with(activity or fragment, etc.)
        .load(urlFromResponse)
        .centerCrop() // If you want to crop it
        .placeholder(R.drawable.loading_spinner) // also optional
        .into(myImageView);