0

This is how normally we retrieve raw data from server with httppost or get. This is one of the tutorial from google search Tutorial link

  1. use a HttpPost to get the data,
  2. convert response to string parse
  3. JSON data, and use it as you want

But what if i want retrieve data and together with related image into my android apps?What is the appropriate method to go for?

This is example of my data.

id    image_name  caption
 1      01.jpg     Abcd

and my image store in somewhere of my server.

upload/background_image/01.jpg

2 Answers 2

2

Convert the image in base64 string in the server side, and retrieve it from the application. then use the following to decode the base64 string into bitmap

public static String encodeTobase64(Bitmap image)
{
    Bitmap immagex=image;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);

   // Log.e("LOOK", imageEncoded);
    return imageEncoded;
}
public static Bitmap decodeBase64(String input) 
{
    byte[] decodedByte = Base64.decode(input, 0);
    return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); 
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks , i think this is what i want , can this conversion done in php(client side)? what if i want to do caching in my apps, will it be difficult?
do you want to cache the images in the android device
Yes , I want to cache it , will it be a problem if i follow your way?
It depends on the size and count of the image.
2

you can response them as url, and when you need the image content, issue another request.

or

you can read the image content, base64_encode it and response as string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.