Skip to content Skip to sidebar Skip to footer

How To Check From A Web If The Versionname Of Apk With The Installed Apk At Device It Is The Same Or Not In Android Studio

I am trying to check at runtime if there is a new version of the app from an url. I have deployed the app at the online domain which is something like this www.test.com/androidapp/

Solution 1:

Jsoup is not for the purpose you are using. Better you upload a json file to your server and get it using okhttp. Example:www.oye.com/update.json Where you may set information for version,What's new,URL,and other info. Otherwise you will have a bad experience using jsoup for checking your app update

Answer Updated JsonFile on your server (Example:www.oye.com/update.json)

{"name":"AppName","size":"8mb","url":"https://www.youall.com/update.apk","version":"1.08"}

Using okhttp

OkHttpClient client=newOkHttpClient();


Request request=newRequest.Builder().url("www.oye.com/update.json").build();

        Callcall= client.newCall(request);
        call.enqueue(newCallback() {
                publicvoidonResponse(Call call, final Response response)throws IOException
                {

JSONObject obj=newJSONObject(reponse.body().string);
                         if(obj.getDouble("version")>yourAppvrrsion){
                             //update avialable
                         }else{
                             //not avialable
                         }


}});

Solution 2:

You should set the latest version name of your app on the domain, e.g 1.0.0, instead of simply uploading the whole apk. Then using PackageManager retrieve the versionName and compare it with the online version.

PackageManagerpackageManager= getPackageManager();
    try {
        PackageInfopackageInfo= packageManager.getPackageInfo(getPackageName(), 0);
        StringlocalVersionName= packageInfo.versionName;

       //Compare with the online versionif(localVersionName  != onlineVersionName){
       //Update the app
       }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

Post a Comment for "How To Check From A Web If The Versionname Of Apk With The Installed Apk At Device It Is The Same Or Not In Android Studio"