My app has to display an image preview from the image data obtained as InputStream from a web service. InputStream is decoded to Bitmap to display in ImageView. This entire flow is working fine in Android 2.2 and 2.3, whereas it’s not functioning with Android 3.0 and 4.0. The bitmap decoded is null in the latter case whereas its fine in 2.x.
Here is the code snippet I use..
ImageView imgView = (ImageView) findViewById(R.id.image);
String imageUrl = "my webservice url";
HttpClient httpClient = new DefaultHttpClient();
HttpGet mHttpGetEntity = new HttpGet(imageUrl);
HttpResponse response;
try {
response = httpClient.execute(mHttpGetEntity);
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
InputStream is = response.getEntity().getContent();
xpp.setInput(is, "UTF-8");
// use xpp for process
imgView.setImageBitmap(BitmapFactory.decodeStream(is));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
How can I make this work even with Android 3.0 above. Please advice.
your code is doing fine on my 4.0. I would say don’t worry about 3.0 since it is unstable version no one will use it.