Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get latest version of android app from Google Playstore?

Question :

I want to get the latest version of my app in production, from Google Playstore. I want to add functionality to force upgrade, if some changes in the latest version require it.

What I have :

I am currently updating the latest version of the app on my server, and forcing the app to request for it and check the version against it. This works. But I do not want to update on my server everytime I release a new version. I want the app to be able to pick up the same information from Google Playstore instead.

What I need :

I can handle the logic at client side (on the app). All I need is an API call to Playstore to get my own app's latest production version. If anyone can help me with some pointers on this, it would be very helpful.

Cheers,

Rohitesh

like image 735
Rohitesh Avatar asked Jan 16 '16 04:01

Rohitesh


People also ask

How do I know if I have the latest version of an app on Android?

Tap on the app info icon (i), and you'll end up in Settings. You'll be in App info for that app; tap on the Advanced dropdown menu. At the bottom, you'll see what version you are using for that app.

How do I download an app from the internal version of Google Play?

Open Play Console. Select an app. On the left menu, select Release > Internal testing > Internal app sharing. On the Uploaders and testers tab, scroll to the “Manage testers” section and check that the option “Anyone you shared the link with can download” is selected (it should be selected by default).


2 Answers

You can check it with Android in-app-update. Android dev guide

like image 192
Junaed Avatar answered Sep 20 '22 00:09

Junaed


There is a trick that you can implement for getting current play store version.

public void getUpdate() {
        final String appPackageName = getPackageName();
        Document doc = null;
        try {
            doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + appPackageName).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Document doc = Jsoup.parse(resString);
        if(doc!=null) {
            Element meta = doc.select("div[itemprop=softwareVersion]").first();
            String content = meta.ownText();
            System.out.println(content);
            Double playStoreVersion = Double.valueOf(content);
            Double currentVersion = getVersionName();
            if (playStoreVersion > currentVersion) {
                try {
                    new AlertDialog.Builder(SplashScreen.this)
                            .setTitle("Alert")
                            .setMessage("Update Is Available.Do You Want To Update?")
                            .setIcon(R.mipmap.ic_launcher)
                            .setCancelable(false)
                            .setPositiveButton("Update",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog,
                                                            int id) {
                                            try {
                                                startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);

                                            } catch (Exception e) {
                                                try {
                                                    startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
                                                } catch (Exception e1) {

                                                }
                                            }
                                            dialog.dismiss();
                                        }
                                    }).setNegativeButton("Not yet", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                            Handler();

                        }
                    }).show();
                    //startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                } catch (android.content.ActivityNotFoundException anfe) {
                    try {
                        startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)), UPDATE_FROM_PLAY_STORE_REQUEST);
                    } catch (Exception e) {
                    }
                }
            } else {
                Handler();
            }
        }else {
            Handler();
        }
}

get the version of our own application.

public Double getVersionName() {
    Double VersionName = 0.0;
    try {
        String vName = SplashScreen.this.getPackageManager().getPackageInfo(SplashScreen.this.getPackageName(), 0).versionName;
        VersionName = Double.valueOf(vName);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return VersionName;
}
like image 34
ChandraShekhar Kaushik Avatar answered Sep 20 '22 00:09

ChandraShekhar Kaushik