2017-04-26 75 views
1

我正在面對從PlayStore獲取我的應用的最新版本代碼的問題。我有應用程序apk以及穿上apk上載的Playstore。現在,當我打電話Play商店中獲取最新版本的移動應用程序,如果提供響應爲:在多個apks的情況下以編程方式從playstore獲取最新應用的版本代碼

它根據設備

因此而改變,有沒有辦法來獲取最新版本移動應用的代碼?

下面是我用來檢索應用程序的最新版本代碼的代碼。

private class GetVersionCode extends AsyncTask<Void, String, String> { 
    @Override 
    protected String doInBackground(Void... voids) { 
     String newVersion = null; 
     try { 
      newVersion = Jsoup.connect("https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName() + "&hl=it").timeout(30000) 
        .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").referrer("http://www.google.com") 
        .get() 
        .select("div[itemprop=softwareVersion]") 
        .first() 
        .ownText(); 
      return newVersion; 
     } catch (Exception e) { 
      return null; 
     } 
    } 

    @Override 
    protected void onPostExecute(String onlineVersion) { 
     super.onPostExecute(onlineVersion); 
     if (onlineVersion != null && !onlineVersion.isEmpty()) { 
      String currentVer = getIntVersionNumber(currentVersion); 
      String onlineVer = getIntVersionNumber(onlineVersion); 
      if (Integer.parseInt(currentVer) < Integer.parseInt(onlineVer)) { 
       showAlertDialog(onlineVersion); 
      } 
     } 
    } 
} 
+0

什麼是不同的版本實際的錯誤? 你不從JSOUP方法或其他東西上面獲取版本號嗎? –

+0

您的案例中不同的版本代碼是預期的行爲,因爲您有多個apks,即移動版和磨損版。 –

+0

@BhupatBheda我沒有從jsoup獲得任何版本代碼,而是它給我的字符串作爲可用的各種版本。 – DPP

回答

1

你「因設備而異」,因爲應用程序運行在設備上

enter image description here

如果有版本號,那麼你可以得到的版本號,否則不可能

+0

好的。它與您的照片中顯示的相同。所以在這種情況下,我如何獲得版本號,因爲我必須告訴用戶每次更新我添加新的apk時?任何解決方案 – DPP

相關問題