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 message and if he/she opt for upgrade I want to update the new version.I want to do all this through my application. Is this possible?
-
question is not clear – Biraj Zalavadia Mar 28 '14 at 10:00
-
If your app is going to be published to the playstore, the OS will update it for you. If you are not planning it to put it on the playstore you will have to create your own method. Where is the app going to be published? – CurlyPaul Mar 28 '14 at 10:03
-
Your question is not clear--Do you have any app in play store with version 1.0 and you want to upload the next version 2.0? – Legendary Genius Mar 28 '14 at 10:08
-
yes sir, but i want t0 update to the user from my application at start time new version is available and download it – user2914699 Mar 28 '14 at 10:11
-
Maybe the answer in this question could help http://stackoverflow.com/questions/12091534/checking-my-app-version-programmatically-in-android-market – CurlyPaul Mar 28 '14 at 10:16
-
@CurlyPaul I believe it is the Google Play app that does this, not the Android OS itself. – Code-Apprentice Jan 11 '17 at 05:21
-
Does this answer your question? [Programmatically check Play Store for app updates](https://stackoverflow.com/questions/25201349/programmatically-check-play-store-for-app-updates) – Tarun Deep Attri May 15 '20 at 17:53
-
Does this answer your question? [Force update of an Android app when a new version is available](https://stackoverflow.com/questions/19244305/force-update-of-an-android-app-when-a-new-version-is-available) – AshuKingSharma Jul 01 '20 at 20:13
10 Answers
I have the same issue but it resolved by JSOUP library. Here is the library download link: http://jsoup.org/download
String newVersion = Jsoup
.connect(
"https://play.google.com/store/apps/details?id="
+ "Package Name" + "&hl=en")
.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();
Log.e("new Version", newVersion);

- 4,498
- 8
- 38
- 59
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 :
<div class="content" itemprop="softwareVersion"> 2.2.0 </div>
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).
Edit:
Google introduced In-app updates lib. It works on Lollipop+ and gives you the ability to ask the user for an update with a nice dialog (FLEXIBLE) or with the mandatory full-screen message (IMMEDIATE).

- 1,241
- 1
- 14
- 16

- 14,718
- 15
- 67
- 108
-
thanks sir ,but i have a problum to palystore link to download application its not download Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=package name")); startActivity(intent); – user2914699 Mar 28 '14 at 10:28
-
I'm not talking about downloading an app but simply checking a web page with DefaultHttpClient to get the version number – grunk Mar 28 '14 at 10:40
-
It is actually bad idea, because you can have different versions available for different devices and the version will be i.e. "Varies with device". – Fenix Voltres Sep 24 '15 at 10:17
Well there is another way I figured out and this is how I am doing it.
HttpPost httppostUserName = new HttpPost("https://androidquery.appspot.com/api/market?app=com.supercell.clashofclans"); //your package name
HttpClient httpclient = new DefaultHttpClient();
HttpResponse responseUser = httpclient.execute(httppostUserName);
String responseStringUser = EntityUtils.toString(responseUser.getEntity(), HTTP.UTF_8);
Log.d(Constants.TAG, "Response: " + responseStringUser);
try {
JSONObject Json = new JSONObject(responseStringUser);
newVersion = Json.getString("version");
} catch (Exception e) {
e.printStackTrace();
}
You will get a clearer view if you paste the url in your browser to see the results.

- 7,986
- 4
- 45
- 57

- 3,543
- 8
- 33
- 59
-
Hello sir , i m not able to get version name from your code. i doesn't get json.. – Vrajesh Jun 12 '15 at 07:00
-
@Vrajesh https://androidquery.appspot.com/api/market?app=com.supercell.clashofclans check this in your browser. Check your package name aswell. – Salmaan Jun 12 '15 at 07:43
-
thnks for the help, give me clarification:: i uploaded app for USA, is this url work (can i get app version and all details in future ) ? – Vrajesh Jun 13 '15 at 05:39
-
@Vrajesh is your app published on play store? If yes, you should be able to see the version and other stuff. Can you share your app's link? – Salmaan Jun 14 '15 at 14:50
-
link: https://play.google.com/store/apps/details?id=com.cloudzon.gratzeez this is the project which is uploaded on play store. – Vrajesh Jun 15 '15 at 10:31
-
@Vrajesh your webservice https://androidquery.appspot.com/api/market?app=com.cloudzon.gratzeez get your app details from where ever you want :) BTW nice app – Salmaan Jun 15 '15 at 10:44
-
Hi am not able to get version of google play store. let me know if anyone have idea. – Teraiya Mayur Oct 05 '15 at 06:50
-
-
You can use the Play Core Library In-app updates to tackle this. You can check for update availability and install them if available seamlessly.
Note that, In-app updates works only with devices running Android 5.0 (API level 21) or higher, and requires you to use Play Core library 1.5.0 or higher.
In-app updates are not compatible with apps that use APK expansion files (.obb files). You can either go for flexible downloads or immediate updates which Google Play takes care of downloading and installing the update for you.
dependencies {
implementation 'com.google.android.play:core:1.5.0'
...
}

- 10,213
- 3
- 52
- 73
EDIT
They have recently changed Google play website and now this code is broken. Avoid this solution or be ready to patch your app whenever Google Play pages change.
Ahmad Arlan's answer is the best answer so far. But if you got here and you try to cut and paste his code you'll go through the same issues I just had, so I might as well just post it here to help others like me.
Make sure you have
INTERNET
permission on yourAndroidManifest.xml
file.<uses-permission android:name="android.permission.INTERNET"/>
Add
JSOUP
dependency to your modulebuild.gradle
.dependencies { compile 'org.jsoup:jsoup:1.10.2' }
Surround the snippet with
try and catch
and don't run it on the main thread.public class MainActivity extends AppCompatActivity { String newVersion; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new FetchAppVersionFromGooglePlayStore().execute(); } class FetchAppVersionFromGooglePlayStore extends AsyncTask<String, Void, String> { protected String doInBackground(String... urls) { try { return Jsoup.connect("https://play.google.com/store/apps/details?id=" + "com.directed.android.smartstart" + "&hl=en") .timeout(10000) .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(); } catch (Exception e) { return ""; } } protected void onPostExecute(String string) { newVersion = string; Log.d("new Version", newVersion); } } }
I posted a copy here of the project on github.

- 1
- 1

- 7,986
- 4
- 45
- 57
-
Got exception - javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. – user3209435 Apr 13 '17 at 06:55
-
@user3209435 Indeed, Google Play changed and now this code is no longer functional. Maybe it is not the best strategy. I no longer use this. We use a call to our backend. – GabrielOshiro Apr 13 '17 at 15:57
This worked for me. Add this dependency.
implementation 'org.jsoup:jsoup:1.8.3'
At onCreate() method use the following code:
try {
String currentVersion="";
currentVersion = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
Log.e("Current Version","::"+currentVersion);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
new GetVersionCode().execute();
Create class GetVersionCode:
private class GetVersionCode extends AsyncTask<Void, String, String> {
@Override
protected String doInBackground(Void... voids) {
String newVersion = null;
try {
Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + context.getPackageName() + "&hl=en")
.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();
if (document != null) {
Elements element = document.getElementsContainingOwnText("Current Version");
for (Element ele : element) {
if (ele.siblingElements() != null) {
Elements sibElemets = ele.siblingElements();
for (Element sibElemet : sibElemets) {
newVersion = sibElemet.text();
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return newVersion;
}
@Override
protected void onPostExecute(String onlineVersion) {
super.onPostExecute(onlineVersion);
if (onlineVersion != null && !onlineVersion.isEmpty()) {
if (onlineVersion.equals(currentVersion)) {
} else {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Update");
alertDialog.setIcon(R.mipmap.ic_launcher);
alertDialog.setMessage("New Update is available");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Update", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
Log.d("update", "Current version " + currentVersion + "playstore version " + onlineVersion);
}
}

- 1,949
- 3
- 20
- 48
Google Play already does this. When you upload a new version of your app, it will either send an alert directly to your users' devices or download the upgrade automatically if the user has this option turned on in the Google Play app.

- 81,660
- 23
- 145
- 268
private void checkForUpdate() {
PackageInfo packageInfo = null;
try { packageInfo=getPackageManager().getPackageInfo(DashboardActivity.this.getPackageName(), 0);
int curVersionCode = packageInfo.versionCode
if (curVersionCode > 1) { // instead of one use value get from server for the new update.
showUpdateDialog();
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
Beware of policy violations, Google will suspend your App if any 3rd party frameworks used for App update, this happened to me recently.

- 2,368
- 3
- 23
- 33
Update 2019 Android Dev Summit
Google introduced In-app updates lib. It works on Lollipop+ and gives you the ability to ask the user for an update with a nice dialog (FLEXIBLE) or with the mandatory full-screen message (IMMEDIATE).
In-app updates works only with devices running Android 5.0 (API level 21) or higher.

- 1,241
- 1
- 14
- 16