在互聯網上嘗試了很多方法,但我的imageView仍然顯示圖像的空白。 希望從URL檢索圖像(下載或參考它),但似乎我錯過了一些東西。 我已激活清單中的INTERNET權限。Android:ImageView從URL加載
icon.setImageResource(R.drawable.portrait_user);
try {
URL url = new URL("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/t1.0-1/c0.0.50.50/p50x50/1499583_10202305028778787_1063740680_n.jpg");
InputStream content = (InputStream)url.getContent();
Bitmap d = BitmapFactory.decodeStream(content);
icon.setImageBitmap(d);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
爲什麼重新發明車輪而不是使用衆多現有的更好的解決方案之一? –