title: Android: How to get image from remote server
body: <p>I am developing an Android app that should get an image from remote server. Am using WAMP as my server and PHP as programming language. I know how to get text data using JSON.</p>
  
  <p>Am not using blob to store image.
  Images have stored in a folder on server. Url of image is stored in db table.</p>
  
  <p>I tried the following snippet, I got this from net but it is not giving any error and also it is not displaying image</p>
  
  <pre><code>HttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost("http://10.0.2.2/sareesProject/returnSareeTypeImageUrls.php");
  response = httpClient.execute(httpPost);
  entity = response.getEntity();
  if(response.getStatusLine().getStatusCode() == 200)
  {
      Log.d("Http Response:", response.toString());
      if(entity != null)
      {
          InputStream instream = entity.getContent();
          JSONObject  jsonObj = new JSONObject(convertStreamToString(instream));
          String base64Image = jsonObj.getString("pprs");
          Toast.makeText(getBaseContext(), base64Image, Toast.LENGTH_LONG).show();
          byte[] rawImage = Base64.decode(base64Image, Base64.DEFAULT);
          bmp = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
      }
  }
  ImageView imageview = (ImageView) findViewById(R.id.flag);
  imageview.setImageBitmap(bmp);
  </code></pre>
  
  <p>The following is my php code</p>
  
  <pre><code> &lt;?php
      error_reporting( E_ALL ^ E_NOTICE ^ E_WARNING);
      $con = mysql_connect("localhost","root","") or die("con error");
      mysql_select_db("sareesdb") or die("db select eror");
      $query = mysql_query("select * from noofpiecesinatype");
      if($row = mysql_fetch_assoc($query))
      {
          $response = $row['imageUrl'];
      }
      $response = base64_encode($response);
      echo '{"pprs":'.json_encode($response).'}';
      mysqli_close($con);
      ?&gt;
  </code></pre>
  
  <p>I checked my php code with html(with out encoding $response value) am getting image there, but not in Android.</p>