【发布时间】:2016-08-15 00:23:35
【问题描述】:
我正在尝试使用 Volley 库和 Dropbox API 编写自动更新。我已经对其进行了设置,以便它读取博客页面并找到这段代码:
if (response != null) {
boolean resp = response.contains("<div class='post-body entry-content' id='post-body-6791062644900393367' itemprop='description articleBody'>\n" +
"1.1.8\n" +
"<div style='clear: both;'></div>");
使用此代码我可以说如果响应小于 1.1.8 则下载更新。我尝试使用这种方法这样做:
if (!resp){My Intent code is here }
但使用此代码,即使版本是最新的,它也会下载更新。
我现在添加了下面的代码来捕获版本号。但我无法弄清楚如何将它与我的 gradle 中的任何一个版本进行比较,并说 如果低于请更新。
Pattern p = Pattern.compile("<div class='post-body entry-content' id='post-body-6791062644900393367' itemprop='description articleBody'>\n" +
"([0-9.]+)\n" +
"<div style='clear: both;'></div>");
Matcher m = p.matcher(response);
if (m.find()) {
String version = m.group();
// more code here
}
是我做错了什么还是需要添加更多代码?我读过我不能使用少于它。这样我也尝试过使用“”比较。如果您认为可能是我的其他代码导致问题,请告诉我,我可以发布更多内容供您查看。
【问题讨论】:
-
我编辑了我的答案,包括完整的工作代码,您只需复制和粘贴即可继续。看看吧,兄弟!我希望这将是您正在寻找的公认答案
标签: java token tokenize string-parsing stringtokenizer