简体   繁体   English

如何获取 Playstore 应用程序版本名称和版本代码 android 应用程序 cordova

[英]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我在 Play 商店中有一个应用程序,如何使用 Cordova 获取 Play 商店应用程序版本名称和版本代码,任何建议表示赞赏

To check updates, you need to take a platform-specific approach要检查更新,您需要采用特定于平台的方法

iOS Approach iOS 方法

  1. You need to send a request to https://itunes.apple.com/lookup?bundleId=BUNDLE_ID您需要向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.获得结果后,您可以从response.data.results[0].version获取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现在,如果版本不同,您可以使用链接https://itunes.apple.com/app/APP_ID将用户发送到应用商店

Android Approach Android 方法

  1. You need to send a request to https://play.google.com/store/apps/details?id=BUNDLE_ID您需要向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现在,如果版本不同,您可以使用链接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. Android 方法是一种基于 DOM 的解决方法,因为我们直接使用tag[6].innerText.trim()访问索引,但对于 iOS,它是一个可靠的方法。

Here is the code to get the version number of the Play store application, as well as how to implement a force update option.这是获取 Play 商店应用程序版本号的代码,以及如何实现强制更新选项。 I've tested it, and it is working perfectly.我已经对其进行了测试,并且运行良好。

  var your_url =YOUR_PLAY STORE APP_URL;
          $.ajax({
            url: your_url,
            type: 'GET',
            success: function(res) {
                let storeVersion =null;
                var doc=null;
                var tag=null;
               var parser = new DOMParser(),
               doc = parser.parseFromString(res, 'text/html');
               if (doc) {
                tag = doc.querySelectorAll(".hAyfc .htlgb");
               if (tag && tag[6]) {
               storeVersion = tag[6].innerText.trim();

               }
               }
               cordova.getAppVersion.getVersionNumber(function(versionNumber){
                var curentVersion = versionNumber;
                var playStoreVersion = tag[6].innerText.trim();
                //alert("loacal version = "+curentVersion+"    "+"playstore version = "+playStoreVersion);
                if(curentVersion<playStoreVersion){
                    navigator.notification.confirm("There is New Version of this application available,Click Upgrade to Update now ?", onConfirm, "Confirmation", "Update,Later");
                }else{
                }
            });
            }
        }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序在Cordova Android应用程序中处于后台时获取用户位置 - Get user location while app is background in cordova android application 如何使用 Cordova 在同一设备上获取其他已安装应用程序的版本? - How to get version of the other installed app on same device using Cordova? 如何将Android / iOS应用程序与Cordova混合应用程序接口 - How To Interface Android/iOS App With Cordova Hybrid Application 如何使用 Javascript 从应用程序 ID 中获取 Android 应用程序的应用程序名称? - How do I get the application name of an Android app from the application ID using Javascript? Cordova / Phonehap-从config.xml获取应用程序版本号 - Cordova/Phonehap - get app version number from config.xml 如何在Cordova Android应用程序中使用gmail登录 - How to sign in using gmail in cordova android application 如何查找导致Android中的Cordova应用程序崩溃的原因? - How to find what crashes a Cordova App in Android? 如何在我的cordova phonegap android应用上从Google云端硬盘获取文件和文件夹列表? - How to get list of files and folders from Google Drive on my cordova phonegap android app? 如何获取浏览器名称,版本? - How to get browser name,version? 科尔多瓦:如何获取应用程序的宽度和高度? - Cordova: How to get width and height of app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM