How to Allow Users to Check for the Latest App Version from Inside the App

How to allow users to check for the latest app version from inside the app?

Google updated play store two months before.
This is the solution working right now for me..

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=" + MainActivity.this.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 (Float.valueOf(currentVersion) < Float.valueOf(onlineVersion)) {
//show anything
}

}

Log.d("update", "Current version " + currentVersion + "playstore version " + onlineVersion);

}
}

and don't forget to add JSoup library

dependencies {
compile 'org.jsoup:jsoup:1.8.3'}

and on Oncreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String currentVersion;
try {
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

new GetVersionCode().execute();

}

that's it..
Thanks to this link

Notify user within app that a new version is available

There is no API or service by when you can check with Google Play what the latest version of your app is.

Instead, you should maintain the latest version code on your server, and have your app check it periodically against its own version code. If the version code is higher on the server, then your app needs to be updated and you can tell the user accordingly.

Check for updates to app, inside that app on Android

Actually, Android Market takes a very good care of updating your application. Users are notified as soon as your update is available, and if they decide to ignore the notification, it's their decision.

If you are looking for alternative methods of updating your application, I'd suggest to check this thread.

Programmatically check Play Store for app updates

Update 17 October 2019

https://developer.android.com/guide/app-bundle/in-app-updates

Update 24 april 2019:

Android announced a feature which will probably fix this problem. Using the in-app Updates API:
https://android-developers.googleblog.com/2018/11/unfolding-right-now-at-androiddevsummit.html

Original:

As far a I know, there is no official Google API which supports this.

You should consider to get a version number from an API.

Instead of connecting to external APIs or webpages (like Google Play Store).
There is a risk that something may change in the API or the webpage, so you should consider to check if the version code of the current app is below the version number you get from your own API.

Just remember if you update your app, you need to change the version in your own API with the app version number.

I would recommend that you make a file in your own website or API, with the version number. (Eventually make a cronjob and make the version update automatic, and send a notification when something goes wrong)

You have to get this value from your Google Play Store page (is changed in the meantime, not working anymore):

<div class="content" itemprop="softwareVersion"> x.x.x  </div>

Check in your app if the version used on the mobile is below the version nummer showed on your own API.

Show indication that she/he needs to update with a notification, ideally.

Things you can do

Version number using your own API

Pros:

  • No need to load the whole code of the Google Play Store (saves on data/bandwidth)

Cons:

  • User can be offline, which makes checking useless since the API can't be accessed

Version number on webpage Google Play Store

Pros:

  • You don't need an API

Cons:

  • User can be offline, which makes checking useless since the API can't be accessed

    • Using this method may cost your users more bandwidth/mobile data
    • Play store webpage could change which makes your version 'ripper' not work anymore.

How to force user to update the app?

Hmm you can do this by below approach.

  1. Add an updated code version of your app to the server
  2. Make a web service that return that version code you placed on
    server

If you have BaseActivity do the third on that else do the third step on that activity that is first Activity or launcher Activity


  1. In onResume method hit that service and get App version code and match that code with current app code. If both are same then it is ok else Prompt the user and take the user out of the app by killing the app.
    NTOE: You can use below code to get the current version of the app that is installed in your device.

    PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    String version = pInfo.versionName;

Hope that helps you.

Detect if new install or updated version (Android app)

public static boolean isFirstInstall(Context context) {
try {
long firstInstallTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;
long lastUpdateTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
return firstInstallTime == lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return true;
}
}

public static boolean isInstallFromUpdate(Context context) {
try {
long firstInstallTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;
long lastUpdateTime = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).lastUpdateTime;
return firstInstallTime != lastUpdateTime;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}

How to force users to update app from play store in Flutter using in_app_update

There is a package for what you want:

https://pub.dev/packages/in_app_update

Sample Image

Android
This plugin integrates the official Android APIs to perform in app updated that were released in 2019: https://developer.android.com/guide/app-bundle/in-app-updates

iOS

iOS does not offer such a functionality. You might want to look into e.g. https://pub.dev/packages/upgrader. If you call the methods above on a iOS device you'll run into a not-implemented exception.

Thanks...

Flutter - How to check is the app has a new version?

I recommend trying out the Firebase Remote Config and update the minimum required version there. It's not a good practice to force update app on every update in the store. Also, some users can see the updated version in given store later than others. This is just how Google Play and AppStore work.

Thus, when you really need to force update the application you can increment the parameter on Firebase e.g. a day after update in the store.

Simple code to trigger the dialog can look as following:

Future<bool> checkUpdates() async {
await remoteConfig.fetch();
await remoteConfig.activateFetched();

final requiredBuildNumber = remoteConfig.getInt(Platform.isAndroid
? 'requiredBuildNumberAndroid'
: 'requiredBuildNumberIOS');

final currentBuildNumber = int.parse(packageInfo.buildNumber);

return currentBuildNumber < requiredBuildNumber;
}

This requires package_info package to be added as well as firebase_remote_config.

To open the app in the store you need to use url_launcher package and just pass URL to your app.



Related Topics



Leave a reply



Submit