我正在使用通过下载从RSS源引用的文件填充的arraylist。我不认为此时它已保存到磁盘。
强制性示例代码:
URL url = new URL("http://someurl.com/rss");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
NodeList postList = doc.getElementsByTagName("item");
thumbIds = new Integer[postList.getLength()];
for (int i = 0; i < postList.getLength(); i++) {
// extract post
Node post = postList.item(i);
Element postElement = (Element) post;
NodeList titleList = postElement.getElementsByTagName("media:thumbnail");
Element titleElement = (Element) titleList.item(0);
String myUrl = titleElement.getAttribute("url").toString();
if(myUrl != null) {
thumbs.add(new BitmapDrawable(fetchBitmap(myUrl)));
}
}
public static Bitmap fetchBitmap(String url) {
URL newurl = null;
try {
newurl = new URL(url);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap returnBitmap = null;
try {
returnBitmap = BitmapFactory.decodeStream(newurl.openConnection()
.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnBitmap;
}
提前感谢!
答案 0 :(得分:2)
我担心答案是否定的。
您只获取/ res文件夹中声明的文件的资源标识符。如果您将Bitmaps下载到您的应用程序并想要存储它们,那么我现在能够想到的唯一解决方案是将它们保存为文件(缓存或外部)或数据库中。