Checking my app version programmatically in Android market
Asked Answered
B

2

27

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.

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.

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?

Begonia answered 23/8, 2012 at 12:24 Comment(2)
i think auto updates is a setting the user can activate or deactivate. in most case, you would rather leave the user settings and not force the user to update if they don't want to, or can'tBeak
Cross link referenceSectorial
W
18

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/.

Specifically, take a look at the Wiki page HowToSearchApps. The response to the query contains version information:

{
  "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": [
...
Wallflower answered 23/8, 2012 at 12:31 Comment(3)
I have not used it, but looking at the comments in the Wiki pages, I am sure there are many people using it (or trying it out).Wallflower
i saw this api but how to check version code with the help of it ?Begonia
The API is not working anymore? For example: androidquery.appspot.com/api/… doesn't answer.Hellcat
B
1

We can do pattern matching for getting the app version from 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:

    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.

Brutalize answered 23/5, 2018 at 3:36 Comment(1)
This is not working anymore.Doff

© 2022 - 2024 — McMap. All rights reserved.