【发布时间】:2012-03-31 05:42:42
【问题描述】:
我的应用必须显示从 Web 服务作为 InputStream 获得的图像数据的图像预览。 InputStream 被解码为 Bitmap 以显示在 ImageView 中。整个流程在 Android 2.2 和 2.3 中运行良好,但在 Android 3.0 和 4.0 中无法正常运行。在后一种情况下,解码的位图为空,而在 2.x 中则很好。
这是我使用的代码 sn-p..
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();
}
即使在 Android 3.0 以上版本中,我如何才能使这项工作正常进行。请指教。
【问题讨论】:
标签: android imageview inputstream android-3.0-honeycomb android-4.0-ice-cream-sandwich