我正在开发一个检查是否有可用更新的应用程序。问题是我的应用程序无法识别自己处于最新版本。
我的服务器上有一个文件,该文件包含最新的版本号 (1.0.1)。我的应用程序版本也是 1.0.1,但是当我检查更新时,我的应用程序表明有更新可用,文本显示最新且安装的版本是 1.0.1。
所以这是我的代码:
(checkupdatebutton)
{
setContentView(R.layout.updater);
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httppost = new HttpGet("http://myserver.com/latestversion.txt");
HttpResponse response;
response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line + "\n");
}
TextView versionupdnew = (TextView)findViewById(R.id.versionupdnew);
//Set text to value of my file (latestversion.txt)
versionupdnew.setText(total);
TextView installedversion = (TextView)findViewById(R.id.versionupdcur);
installedversion.setText(R.string.version);
TextView title = (TextView)findViewById(R.id.title);
if(installedversion.equals(versionupdnew))
{
//Current version is latest
title.setText("No update needed!");
Button buttonUpdate = (Button)findViewById(R.id.buttonUpdate);
buttonUpdate.setEnabled(false);
}else{
title.setText("New version is available!");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}