我有这个问题我自己,从来没有找到一个很好的答案,所以你的代码让我看着办吧!
您正在提取的InputStream实际上是JSON格式(例如{“id”:4646546,“name”:“ian”,“profile_image_url”:“http://pbs.twimg.com/profile_images/1138330557/ian-straw_normal.jpg”})。所以你不能只从它创建一个drawable。 Twitter API文档给出了一个示例结果:https://dev.twitter.com/rest/reference/get/users/show。
如果你想以原始大小获取图像,你可以摆脱'_normal'。
使用此profile_image_url,您可以获取您感兴趣的图像。您可以使用Android Query或Picasso来执行此操作。你也可以做另一个HttpRequest,只要你不在主UI线程上做。
你的代码变得(我忽略了可读性try/catch块):
HttpClient client = new DefaultHttpClient();
HttpGet verifyGet = new HttpGet(
"https://api.twitter.com/1.1/users/show.json?screen_name=" + handle);
ParseTwitterUtils.getTwitter().signRequest(verifyGet);
HttpResponse response = client.execute(verifyGet);
InputStream is = response.getEntity.getContent();
JSONObject responseJson = new JSONObject(IOUtils.toString(is));
url = responseJson.getString("profile_image_url");
final AQuery androidQuery = new AQuery(this);
//fetch and set the image from internet, cache with file and memory
androidQuery.id(R.id.image1).image(url);