当前位置:编程学习 > wap >>

android 自动更新升级的问题

     大家好,关于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系统提示更新程序,点击更新,弹出系统进度条,之后说安装完成,进去之后如上面所说,里面内容没变化。 Android 应用 --------------------编程问答-------------------- 下载到SD卡上试试 --------------------编程问答-------------------- 先搞清楚你在服务器上的31版本是不是正确 --------------------编程问答-------------------- 服务器上的APK就是不对的感觉 --------------------编程问答-------------------- 没有 SD卡  服务器APK不对是什么意思,2个APK都是直接从eclipse 工程里面bin目录下copy出来的 ,另外 我又使用签名生产2个apk,也是一样的。不觉的签名有问题。 --------------------编程问答-------------------- 你直接装服务器上的版本对不对?我自动升级没出现过这么扯的情况,想想也不大可能啊 --------------------编程问答-------------------- 你先确认一下 手机里面data/app下面的odex或者apk时间和大小对不对
如果都是和服务器上的一样 上log吧 
1.原始app启动的log
2.下载到升级完成的log
3.新app启动的log

filter全开 尤其是要注意packagemanager和package name的部分
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,