gpt4 book ai didi

android - 从 Android 3.0 及更高版本的 Web 服务获取的 InputStream 加载 ImageView 的问题

转载 作者:太空狗 更新时间:2023-10-29 13:36:27 26 4
gpt4 key购买 nike

我的应用程序必须根据从 Web 服务作为 InputStream 获取的图像数据显示图像预览。 InputStream被解码为Bitmap显示在ImageView中。整个流程在 Android 2.2 和 2.3 中运行良好,但在 Android 3.0 和 4.0 中无法运行。解码后的位图在后一种情况下为空,而在 2.x 中则很好。

这是我使用的代码 fragment ..

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 以上的情况下,我怎样才能使它工作。请指教。

最佳答案

你的代码在我的 4.0 上运行良好。我会说不要担心 3.0,因为它是不稳定的版本,没有人会使用它。

关于android - 从 Android 3.0 及更高版本的 Web 服务获取的 InputStream 加载 ImageView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9953348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com