我正在使用通过下载从 RSS 提要引用的文件填充的数组列表。我不认为在这一点上它曾经保存到磁盘。
- 如果我不保存到磁盘,实际上我是否会有资源标识符?
- 如果是这样,我将如何检索它?
强制性示例代码:
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;
}
提前致谢!