Это то, что я сделал, чтобы получить изображения вместе с данными.Я выкладываю это так, что если это может кому-то помочь.
Это часть скрипта PHP, которая отправляет данные на стороне сервера:
$i=0;
//$sql contains the result from the query of the data
while($row=mysql_fetch_array($sql)){
$output[]=$row;
//Here we fetch the image from the files table
$query = "SELECT path, type FROM FILES WHERE poi_id = '" . mysql_real_escape_string(trim($output[$i][0])) . "'";
$r = mysql_query($query);
$img = mysql_fetch_array($r);
$bin = base64_encode_image($img[0]);
//Let's append the image and the type to the data output.
$output[$i]['img'] = $bin;
$output[$i]['type'] = $img[1];
$i++;
}
//This method sends the response to the Android app
//You can just use echo(json_encode($output));
RestUtils::sendResponse(200, json_encode($output), 'application/json');
А затем в приложении Android после анализа JSON вы можете сохранить строку base64как изображение для файловой системы, например:
public void createImage(String image, String name){
try{
byte[] imageAsBytes = Base64.decode(image.getBytes(), Base64.DEFAULT);
Bitmap img_bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
FileOutputStream fos = openFileOutput(name, Context.MODE_WORLD_READABLE);
img_bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
}
catch(Exception e){
e.printStackTrace();
}
}