Updating an application OTA
- by Bostjan
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