Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms popup "New Version Available"

I am working on Xamarin.forms Android Project, I am searching away to display a pop up for user:

New Version Available

when user try to open an Application and a new update is available on play-store .

like image 959
Mohamad Mahmoud Avatar asked Feb 18 '17 13:02

Mohamad Mahmoud


2 Answers

I think the easiest thing would be to have a web service on your own server that returns the current version number, unfortunately you would need to update this version number any time you update the app in the store.

like image 134
Bill Reiss Avatar answered Sep 25 '22 23:09

Bill Reiss


Create a text file with the latest version number in a GitHub Gist account.

Get the raw URL

string 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;
        }
    }

which will returns the latest version of your app. and check with the existing app version in activity

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

but you have to update this version number any time you update the app in the play store.

like image 23
Shyju M Avatar answered Sep 22 '22 23:09

Shyju M