我正在尝试从 Last.fm 获取艺术家图像并将其应用到ImageView
,但没有返回任何图像。我不确定我在这里做错了什么。
private void setLastFmArtistImage() {
try {
String imageurl = "http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist="
+ URLEncoder.encode("Andrew Bird")
+ "&api_key="
+ APIKEY
+ "&limit=" + 1 + "&page=" + 1;
InputStream in = null;
Log.i("URL", imageurl);
URL url = new URL(imageurl);
URLConnection urlConn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.connect();
in = httpConn.getInputStream();
Bitmap bmpimg = BitmapFactory.decodeStream(in);
mArtistBackground.setImageBitmap(bmpimg);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}