Search code examples
javascriptandroidcordova

How to get playstore app verson name and version code android application cordova


i have one app in the play store, how can get play store application version name and version code using Cordova, any suggestion appreciated


Solution

  • To check updates, you need to take a platform-specific approach

    iOS Approach

    1. You need to send a request to https://itunes.apple.com/lookup?bundleId=BUNDLE_ID
    2. Once you get the result, you can fetch the version from response.data.results[0].version and then compare it with the local version.
    3. Now, if the version is different, you can send the user to the app store using the link https://itunes.apple.com/app/APP_ID

    Android Approach

    1. You need to send a request to https://play.google.com/store/apps/details?id=BUNDLE_ID
    2. Once you get the result, you can extract the version using the snippet below.
    3. Now, if the version is different, you can send the user to the app store using the link https://play.google.com/store/apps/details?id=BUNDLE_ID

    snippet

    var parser = new DOMParser(),
      doc = parser.parseFromString(response.data, 'text/html');
    if (doc) {
      var tag = doc.querySelectorAll(".hAyfc .htlgb");
      if (tag && tag[6]) {
        let storeVersion = tag[6].innerText.trim();
        if (local_version != storeVersion) {
          // send to stroe
        }
      }
    }
    

    Android approach is rather a DOM-based workaround as we are accessing the index directly using tag[6].innerText.trim(), but for iOS, it's a solid one.