android 自动更新升级的问题

Smile__LV 2013-05-13 11:08:33
大家好,关于android 升级的问题想问下大家,求解答,先言谢了。。
我目前手机上的app版本的30,服务器上的app是31.每一次app启动的时候发送信息区服务器上获取数据,其中 服务器会给过来当前服务器app版本,比对如果高于当前app则启动升级程序。
升级的时候提示成功了。其实却失败了。情况是。应用程序列表的图标和下面的字体都变化了,程序大小也变化了。但是进去之后UI内容没变化。我试验了很多次,卸载程序或者打成apk安装,或者eclipse安装,都一样。确信的是服务器上的Apk下载成功了。我的程序大致逻辑是:
要升级的时候启动一个线程,下载服务器上的apk,如下:

/**
* 下载新程序
*/
public void appUpdate(Context context){
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGe("服务器地址"+"/update/XXX.apk");
HttpResponse response;
InputStream is = null;
FileOutputStream fileOutputStream = null;
try {
response = httpClient.execute(get);
HttpEntity entity = response.getEntity();
is = entity.getContent();
long len = entity.getContentLength();
if(is!=null){
fileOutputStream = context.openFileOutput("XX.apk",
Context.MODE_WORLD_READABLE+Context.MODE_WORLD_WRITEABLE);
byte[] buf = new byte[1024];
int ch = -1;
while((ch = is.read(buf)) != -1){
fileOutputStream.write(buf, 0, ch);
}
}
fileOutputStream.flush();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{

if(is != null){
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

下载 完成后,在handler里面 更新。

final Handler handler = new Handler() {

@Override
public void handleMessage(Message msg) {
try {
switch (msg.what) {
case 1:
progressDialog.dismiss();
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(
"/data/data/包名/files/XXX.apk");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri,
"application/vnd.android.package-archive");
context.startActivity(intent);
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}


当程序启动,android系统提示更新程序,点击更新,弹出系统进度条,之后说安装完成,进去之后如上面所说,里面内容没变化。
...全文
159 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Smile__LV 2014-10-13
  • 打赏
  • 举报
回复
结贴,这是本人的一个低级失误、超低级。
妖怪 2013-05-16
  • 打赏
  • 举报
回复
你先确认一下 手机里面data/app下面的odex或者apk时间和大小对不对 如果都是和服务器上的一样 上log吧 1.原始app启动的log 2.下载到升级完成的log 3.新app启动的log filter全开 尤其是要注意packagemanager和package name的部分
  • 打赏
  • 举报
回复
你直接装服务器上的版本对不对?我自动升级没出现过这么扯的情况,想想也不大可能啊
tcmakebest 2013-05-14
  • 打赏
  • 举报
回复
先搞清楚你在服务器上的31版本是不是正确
Smile__LV 2013-05-14
  • 打赏
  • 举报
回复
没有 SD卡 服务器APK不对是什么意思,2个APK都是直接从eclipse 工程里面bin目录下copy出来的 ,另外 我又使用签名生产2个apk,也是一样的。不觉的签名有问题。
儿大不由爷 2013-05-14
  • 打赏
  • 举报
回复
下载到SD卡上试试
zhjh5555 2013-05-14
  • 打赏
  • 举报
回复
服务器上的APK就是不对的感觉

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧