Leon Armstrong
Leon Armstrong

Reputation: 1303

Retrieve data from mysql php to Android

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

Upvotes: 0

Views: 493

Answers (2)

Pramod J George
Pramod J George

Reputation: 1723

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); 
}

Upvotes: 2

goosman.lei
goosman.lei

Reputation: 456

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

Upvotes: 2

Related Questions