Puneet
Puneet

Reputation: 611

Force update my android application

I am trying to force update my application before login, if there is any updated version available. I can check for update and able to install application in device, I replace my old version with updated one, at the end of all this process I want to open/invoke my application automatically not manually, (I can open my application manually), I can not use sqlite database to maintain somedata from application or any other APK which will force to invoke my application forcefully.

Any suggestion would be highly appreciable.

Thanks.


As I mentioned in my question that i can update application by installing new apk file from my server, even i know that android market handles the installation and will ask to invoke application, but in my case I have to do the same on my staging server to test my application by process. I am able to check for update and install application from my staging server, to updated apk installation my old version get uninstall and there is no way I have to invoke my new version application.

Any suggestion would be appreciable.

Upvotes: 4

Views: 6086

Answers (2)

Giedrius Šlikas
Giedrius Šlikas

Reputation: 1201

First of app you need to have an api how to track does the user version is outdated..

For example you are sending your app current version to an API like that:

String version = String.valueOf(BuildConfig.VERSION_CODE);

if response.body().isUpdateRequired() is true so you need to call this allert bellow:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(SplashActivity.this);
                alertDialog.setTitle("Please update your app");
                alertDialog.setMessage("This app version is not supported any longer. Please update your app from the Play Store.");
                alertDialog.setPositiveButton("UPDATE NOW", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        final String appPackageName = getPackageName();
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                        } catch (android.content.ActivityNotFoundException anfe) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                        }
                    }
                });
                alertDialog.show();

Upvotes: 0

Sharmilee
Sharmilee

Reputation: 1295

You could easily call a web service from your app to find out if a newer version is available and to direct users to download it via the Android Browser. One advantage of this approach is some control over upgrade rate rather than the 'big bang' approach which is all that is supported by the Market.

something like

http://example.com/update.jsp?versionCode=3

where the versionCode comes from the manifest version. Then I would have the service either return blank (no update) or a URL to which the user should be directed to get the new apk.

You can have version code from

        getPackageManager().getPackageInfo(getPackageName(), 0).versionCode 

Please trigger a new intent to visit the URL. The user then gets sent to the browser which downloads the apk

Upvotes: 2

Related Questions