android 自动更新的时候出现解析程序包时出现问题,签名是一样的,apk也下载成功是完整的,但是有的手机自动安装的时候就会报解析程序包时出现问题,有的手机却能自动安装成功。在下载目录里面手动安装就能安装成功。。何解  问题解决再送100分代码如下:
new Thread() {
public void run() {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
try {
response = client.execute(get);
HttpEntity entity = response.getEntity();
int length = (int) entity.getContentLength(); // 获取文件大小
pBar.setMax(length); // 设置进度条的总长度
InputStream is = entity.getContent();
if (is != null) {
File file = new File(
Environment.getExternalStorageDirectory(),
"Health Manager.apk");
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[32]; 
int ch = -1;
int process = 0;
while ((ch = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, ch);
process += ch;
pBar.setProgress(process); //实时更新进度了!
}
}
fileOutputStream.flush();
is.close();
if (fileOutputStream != null) {
fileOutputStream.close();
}
down();
} catch (Exception e) {
e.printStackTrace(); try {
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
myHandler.sendEmptyMessage(5);
}
}.start();void down() {
myHandler.post(new Runnable() {
public void run() {
pBar.cancel();
update();
}
});
} // 安装文件,一般固定写法
void update() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "Health Manager.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
}

解决方案 »

  1.   


    你看下这个帖子,好像是没有执行权限
    http://bbs.csdn.net/topics/380117090
      

  2.   

    应该是权限问题吧,lz不防这样验证一下。
    在模拟器上是吧,
    adb push HealthManager.apk /data/local/tmp/   
    chmod 777 /data/local/tmp
    chmod 777 /data/local/tmp/HealthManager.apk然后把代码里的 HealthManager.apk 改为 /data/local/tmp/HealthManager.apk , 再试下看吧
      

  3.   

    在真机上与模拟器上是一致的, 手机上开启“允许调试”, 然后adb的操作与模拟器是一样的。
      

  4.   

       想哭了  没用过adb  命令  求大神
      

  5.   

    按这个来, 打开cmd:
    adb devices
    若手机连接ok, 这个命令执行后,在命令行下会输出设备。
    adb push d:\\test.apk /data/local/tmp/
    adb shell 进入到手机命令行
    chmod 777 /data/local/tmp/test.apk如果觉得上面有困难,就这样:
    在代码里,将apk放到context.getFilesDir().getAbsolutePath()下,并赋于可执行权限。
    代码里用到文件时,也用context.getFilesDir().getAbsolutePath() + “/" + "test.apk"
      

  6.   

    建议验证一下MD5值 或者用 Application API 打开这个APK文件 如果能返回Application Info信息说明包是完整的 否则就是下载的包丢数据了。