Я просто использую это, и в моем случае это прекрасно работает.
URL newurl;
try
{
newurl = new URL("http://www.russiawear.com/components/com_virtuemart/shop_image/product/youth_russia_usa_4e2f7f78b543c.jpg");
bitmap = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Обновление:
Код для скачивания файла с URL,
try
{
URL url = new URL("http://www.russiawear.com/components/com_virtuemart/shop_image/product/youth_russia_usa_4e2f7f78b543c.jpg"); //you can write here any link
File file = new File("/sdcard/temp.jpg");
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1)
{
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
}
catch (IOException e)
{
Log.d("ImageManager", "Error: " + e);
}
Затем создайте растровое изображение, используя файл,
bitmap = BitmapFactory.decodeFile("/sdcard/temp.jpg");