views:

87

answers:

2

I'm developing an application that will be available from a website (market probably as well). The problem I'm having at the moment is how to handle the updates to the app. I know how to check the version against the current one and I know if I need to update it. Question is...how?

Is there a way I can download an APK from the website and start the install process? The user will have to confirm of course, but I just want to be able to start it for him. At the moment I'm doing this:

private void doUpgrade() {
    // TODO Auto-generated method stub
    Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.upgrade));
    builder.setIcon(R.drawable.help);
    builder.setMessage(getString(R.string.needUpgrade));
    builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

            Map<String, String> data = new HashMap<String, String>();

            try {
                HttpResponse re = Registration.doPost("http://www.android-town.com/appRelease/AndroidTown.apk",data);

                int statusCode = re.getStatusLine().getStatusCode();
                closeApp();

            } catch (ClientProtocolException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), getString(R.string.noURLAccess), Toast.LENGTH_SHORT).show();
                closeApp();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), getString(R.string.noURLAccess), Toast.LENGTH_SHORT).show();
                closeApp();
            }
        }
    });
    builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.cancel();
            closeApp();
        }
    });
    builder.show();
}

But it doesn't really do anything...should I open a webView with the URL? A new runnable thread? Any other way? Please help :)

Cheers

+1  A: 

Just a note that this isn't likely to work well: most devices come with the "Allow apps from non-Market sources" option disabled (under Settings > Applications).

This means that when you launch the intent to install the app, the user will get a warning dialog and the install will fail.

While you can check against an external source for new updates (e.g. checking a text file on your server) and notify the user, I would redirect them to the Android Market itself to do the upgrade.

Christopher
Hm...that's a shame. But I guess if there's no other way it'll have to do. It's just that for testing purposes it would be really nice to have such a feature and not have to get the beta testers to download the apk and the transfer it to the phone and install it...
Bostjan
If it's only for beta testers, I'm sure you can get them to enable the "non-Market" option..
Christopher
+2  A: 

Easiest is just to launch an Intent to open the download URL in the Browser. This will download the APK and the user can then install it by clicking on it in the download manager.

You are saying that this will handle OTA separate to the market so the user should already have disabled "Allow apps from non-Market sources" when they initially installed your app.

alexanderblom
Is there an echo in here? ;)
Christopher
My understanding is that you are suggesting that he should still download the apk himself and then install it from disk.
alexanderblom