Updating an application OTA
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
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.
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.
As everyone has said "Allow apps from non-Market sources" option could be a real pain for you as people other than beta testers or like them would not be intrested to check this option for varoius reasons. Try Testflight, it should help. https://testflightapp.com/android/
精彩评论