Android programmatically update application when a new version is available

前端 未结 9 1984
别那么骄傲
别那么骄傲 2020-12-01 08:45

Within my application, I want to check if there is any updated version of my application is in the app store. If there is any, then have to inform the user through an alert

9条回答
  •  臣服心动
    2020-12-01 09:13

    Google does not provide any API for that.

    Nevertheless , you can make an http request on the web version of the playstore (https://play.google.com/store/apps/details?id=your.namespace)

    To make the request you can use DefaultHttpClient

    Once you get the page content you should parse it (jsoup is a good solution) and search for :

    2.2.0

    Once you find this part of the page , you can extract the version number and compare it with the one available in your app :

    try
    {
        String version = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
        if( ! version.equals(versionFromHTML))
        {
            Toast.makeText(this, "New version available on play store", Toast.LENGTH_SHORT);
        }
    
    }
    catch (NameNotFoundException e)
    {
        //No version do something
    }
    

    For the HTML parsing part , have a look here

    Keep in mind that everybody won't see the new version in the same time. It could take time to be propagated (probably because of cache).

提交回复
热议问题