我正在尝试制作一个显示我网站上的最新消息的 android 应用程序,我对这两件事特别感到困惑?
1.每次手机自动联网时,我如何才能从我的网站获取新闻?
2.我将如何存储这些信息并随后将其用于设备上的更新?
我从谷歌找到了这段代码,我是否朝着正确的方向前进?:
public abstract class BaseFeedParser implements FeedParser {
// names of the XML tags
static final String PUB_DATE = "pubDate";
static final String DESCRIPTION = "description";
static final String LINK = "link";
static final String TITLE = "title";
static final String ITEM = "item";
final URL feedUrl;
protected BaseFeedParser(String feedUrl){
try {
this.feedUrl = new URL(feedUrl);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
protected InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}