目前,我正在检查应用程序版本代码,并将其与我服务器上的最新版本代码进行匹配,并根据此匹配发送用户从Android市场获取最新更新。
它运行良好,但我的问题是我必须手动更改服务器上的最新版本代码,我不知道新版本的APK
何时在市场上被激活。
有没有办法直接检查Android市场中应用程序的版本代码,以便在新apk激活时直接将用户发送到市场?
Google Play不提供任何用于检索元数据的官方API。但是,您可以在http://code.google.com/p/android-market-api/.查看非官方API
具体来说,看看Wiki页面HowToSearchApps。对查询的响应包含版本信息:
{
"app": [
{
"rating": "4.642857142857143",
"title": "Ruboto IRB",
"ratingsCount": 14,
"creator": "Jan Berkel",
"appType": "APPLICATION",
"id": "9089465703133677000",
"packageName": "org.jruby.ruboto.irb",
"version": "0.1",
"versionCode": 1,
"creatorId": "\"Jan Berkel\"",
"ExtendedInfo": {
"category": "Tools",
"permissionId": [
...
我们可以进行模式匹配以从playStore获取应用程序版本。
匹配来自google playstore ie的最新模式
private String getAppVersion(String patternString, String inputString) {
try{
//Create a pattern
Pattern pattern = Pattern.compile(patternString);
if (null == pattern) {
return null;
}
//Match the pattern string in provided string
Matcher matcher = pattern.matcher(inputString);
if (null != matcher && matcher.find()) {
return matcher.group(1);
}
}catch (PatternSyntaxException ex) {
ex.printStackTrace();
}
return null;
}
private String getPlayStoreAppVersion(String appUrlString) {
final String currentVersion_PatternSeq = "<div[^>]*?>Current\\sVersion</div><span[^>]*?>(.*?)><div[^>]*?>(.*?)><span[^>]*?>(.*?)</span>";
final String appVersion_PatternSeq = "htlgb\">([^<]*)</s";
String playStoreAppVersion = null;
BufferedReader inReader = null;
URLConnection uc = null;
StringBuilder urlData = new StringBuilder();
final URL url = new URL(appUrlString);
uc = url.openConnection();
if(uc == null) {
return null;
}
uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
inReader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
if (null != inReader) {
String str = "";
while ((str = inReader.readLine()) != null) {
urlData.append(str);
}
}
// Get the current version pattern sequence
String versionString = getAppVersion (currentVersion_PatternSeq, urlData.toString());
if(null == versionString){
return null;
}else{
// get version from "htlgb">X.X.X</span>
playStoreAppVersion = getAppVersion (appVersion_PatternSeq, versionString);
}
return playStoreAppVersion;
}
我通过这个解决了这个问题。希望有帮助。