我无法从 url 获取收藏图标。我的链接看起来像我拥有 android 权限并尝试重新启动我的模拟器。但仍然是相同的结果。网址是
http://www.feeds.bbci.co.uk/favicon.ico
我试过这个
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
但错误是
connection.connect();
例外是
java.net.UnknownHostException: www.feeds.bbci.co.uk
更新*
将链接更改为
URL url = new URL("HTTP://bbc.co.uk/favicon.ico");
但现在得到空值
Bitmap myBitmap = BitmapFactory.decodeStream(input);