Currently I'm checking the app version code on launch and match it with latest version code on my server and based on this matching I send user to get latest update from Android market.
目前我正在检查启动时的应用版本代码并将其与我服务器上的最新版本代码相匹配,并根据此匹配我发送用户以获取Android市场的最新更新。
It's working well but my problem is that I have to manually change the latest version code on my server and I don't know exactly when new version of APK
gets activated in market.
它运行良好,但我的问题是我必须手动更改我的服务器上的最新版本代码,我不知道什么时候新版本的APK在市场上被激活。
Is there any way to check version code of app in Android market directly so that I can send user directly to market when new apk gets activated?
有没有办法直接在Android市场上检查应用程序的版本代码,以便我可以在新的apk被激活时将用户直接发送到市场?
2 个解决方案
#1
16
Google Play does not provide any official APIs for retrieving metadata. You could however, check the unofficial API at http://code.google.com/p/android-market-api/.
Google Play不提供任何用于检索元数据的官方API。但是,您可以访问http://code.google.com/p/android-market-api/查看非官方API。
Specifically, take a look at the Wiki page HowToSearchApps. The response to the query contains version information:
具体来说,看看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": [
...
#2
1
We can do pattern matching for getting the app version from playStore.
我们可以进行模式匹配,以便从playStore获取应用版本。
To match the latest pattern from google playstore ie <div class="BgcNfc">Current Version</div><span class="htlgb"><div><span class="htlgb">X.X.X</span></div>
we first have to match the above node sequence and then from above sequence get the version value. Below is the code snippet for same:
匹配google playstore的最新模式,即
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;
}
I got this solved through this. Hope that helps.
我通过这个解决了这个问题。希望有所帮助。
#1
16
Google Play does not provide any official APIs for retrieving metadata. You could however, check the unofficial API at http://code.google.com/p/android-market-api/.
Google Play不提供任何用于检索元数据的官方API。但是,您可以访问http://code.google.com/p/android-market-api/查看非官方API。
Specifically, take a look at the Wiki page HowToSearchApps. The response to the query contains version information:
具体来说,看看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": [
...
#2
1
We can do pattern matching for getting the app version from playStore.
我们可以进行模式匹配,以便从playStore获取应用版本。
To match the latest pattern from google playstore ie <div class="BgcNfc">Current Version</div><span class="htlgb"><div><span class="htlgb">X.X.X</span></div>
we first have to match the above node sequence and then from above sequence get the version value. Below is the code snippet for same:
匹配google playstore的最新模式,即
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;
}
I got this solved through this. Hope that helps.
我通过这个解决了这个问题。希望有所帮助。