Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking my app version programmatically in Android market

Tags:

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?

like image 738
mrYogi Avatar asked Aug 23 '12 12:08

mrYogi


People also ask

How do you find the version of an app on Android?

Android System SettingsOnce in Settings, tap Apps and notifications (or your phone manufacturer's name it). When you're in there, tap See all xyz apps (where xyz is the number of apps you have installed). Now scroll down until you find the app you want to find the version for. Then tap it in the list.

How do you know what version of an app is in an app?

Android SettingsOpen the Settings app on your Android device. Open the "Applications" and/or "Application Manager" section. Tap on your app to select it. The App Settings Panel has multiple options including App Version, Notifications, and Location.

Is there any official API to get app details from the Play Store?

Try this google official api: github.com/googlesamples/android-play-publisher-api/tree/master/…


2 Answers

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": [ ... 
like image 76
Rajesh Avatar answered Sep 23 '22 20:09

Rajesh


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.

like image 30
DRK Avatar answered Sep 22 '22 20:09

DRK