我正在开发一个可从网站(市场也可能)获得的应用程序。我目前遇到的问题是如何处理应用程序的更新。我知道如何对照当前版本检查版本,并且知道是否需要更新它。问题是……如何?
有没有办法可以从网站下载 APK 并开始安装过程?当然,用户必须确认,但我只想能够为他启动它。目前我正在这样做:
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();
}
但它并没有真正做任何事情......我应该用 URL 打开一个 webView 吗?一个新的可运行线程?还有什么办法吗?请帮忙 :)
干杯