日期:2014-05-18  浏览次数:20669 次

手机访问action下载apk文件 安装是出错:解析包时出现错误
手机访问action下载apk文件 安装是出错:解析包时出现错误。
电脑上用浏览器直接下载安装在手机上是好的,但用手机访问action下载下来的文件与原文件大小不一致,且安装时出现错误提示:解析包时出现错误。
action代码如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
URL downUrl = new URL("/APPDown/android/HGT.apk");
        URLConnection conn = downUrl.openConnection();
        InputStream is = conn.getInputStream();
        BufferedInputStream in = new BufferedInputStream(is);
        response.addHeader("Content-Disposition", "attachment;filename=" + "HGT.apk");
        //response.setContentType("application/vnd.android.package-archive");
        response.addHeader("Content-Type", "application/vnd.android.package-archive");
        OutputStream outputStream = response.getOutputStream();
        byte[] data = new byte[1024];
        int size = 0;
        int l = 0;
        while ((l = in.read(data)) > 0) {
            size += l;
            outputStream.write(data, 0, l);
        }
        response.addHeader("Content-Length", size + "");
        outputStream.flush();
        outputStream.close();
        in.close();
        is.close();
return null;
}
文件可以正常下载到手机。但安装失败。

------解决方案--------------------