5

は、私は、ユーザーのためにポップアップを表示するように離れて探しています:Xamarin.Formsポップアップ「新バージョンが公開」

新バージョンが公開

ユーザーがアプリケーションを開こうとしたときに、新しい更新がプレイストアで利用可能になったとき。

+2

あなたはホッケーのアプリをチェックしましたか? –

+0

は、私は多分私は –

+1

を、それを使用します。..それについて読んで、なぜあなたが最初の場所でこれをやりたいですか?あなたのアプリを公開すると、ストアは自動的に新しいバージョンに更新されませんか? – SilentStorm

答えて

7

私は最も簡単な方法は、現在のバージョン番号を返す独自のサーバー上のWebサービスを持っているだろう、残念ながらあなたは、このバージョン番号にあなたが店でアプリを更新随時更新する必要があると思います。

+0

THXをそれを試していなかった、私はあなたがより多くの説明 –

1
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=" + SplashActivity.this.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 newVersion; 
     } 
    } 

    @Override 
    protected void onPostExecute(String onlineVersion) { 
     super.onPostExecute(onlineVersion); 
     String currentVersion = null; 
     try { 
      currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; 
     } catch (PackageManager.NameNotFoundException e) { 
      e.printStackTrace(); 
     } 
     if (onlineVersion != null && !onlineVersion.isEmpty()) { 
      if (Float.valueOf(currentVersion) < Float.valueOf(onlineVersion)) { 

        final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SplashActivity.this); 
        alertDialogBuilder.setTitle("Product Update"); 
        alertDialogBuilder.setMessage("A new version is available. Would you like to Upgrade now? (Current: "+currentVersion+" Latest: "+onlineVersion+")"); 
        alertDialogBuilder.setPositiveButton("ok", 
          new DialogInterface.OnClickListener() { 
           @Override 
           public void onClick(DialogInterface arg0, int arg1) { 
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+SplashActivity.this.getPackageName()))); 
           } 
          }); 

        alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          alertDialogBuilder.setCancelable(true); 
          finish(); 
          loginUserCheck(); 
         } 
        }); 

        AlertDialog alertDialog = alertDialogBuilder.create(); 
        alertDialog.show(); 
      } 
+0

はあなただけplaystore、チェックからのアプリの新バージョンを取る見つけることを好む置きますあなたの現在のバージョンがアプリ版よりも大きい場合は、ポップアップを表示するだけです。 –

+0

を追加してください可能性があり、ダイナミックソリューション –

2

GitHub Gistアカウントに最新のバージョン番号のテキストファイルを作成します。

生のURLに

文字列のURL = "https://gist.githubusercontent.com/YOUR_ACCOUNT_NAME/0df1fa45aa11753de0a85893448b22de/raw/UpdateInfo.txt" を取得します。

private static async Task<string> GetLatestVersion(string URL) 
    { 
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(URL)); 
     request.ContentType = "application/json"; //i am using a json file 
     request.Method = "GET"; 
     request.Timeout = 20000; 
     // Send the request to the server and wait for the response: 
     try 
     { 
      using (WebResponse response = await request.GetResponseAsync()) 
      { 
       // Get a stream representation of the HTTP web response: 
       using (Stream stream = response.GetResponseStream()) 
       {      
        StreamReader reader = new StreamReader(stream); 
        return reader.ReadToEnd(); 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      return string.Empty; 
     } 
    } 

あなたのアプリの最新バージョンが返されます。

var versionName = Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName; 
     var currentVer = double.Parse(versionName); 

ですが、プレイストアでアプリを更新するときはいつでもこのバージョン番号を更新する必要があります。

+0

良い解決策。しかし、私はまだダイナミックなソリューションを好む –

関連する問題