下载完安装的时候出现“解析包时出现问题”
请问下,为什么我下载下来(apk文件)的文件大小都是对的,也关闭了。但是安装的时候总是“解析包时出现问题”没法安装呢
@Override
public void run() {
HttpURLConnection connection = null;
InputStream inputStream = null;
RandomAccessFile file = null;
try {
if(!threadDAO.exists(mThreadInfo.getUrl(), mThreadInfo.getId())) {
threadDAO.insert(mThreadInfo);
}
URL url = new URL(mThreadInfo.getUrl());
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(3000);
connection.setReadTimeout(3000);
connection.setRequestMethod("GET");
int start = mThreadInfo.getStart() + mThreadInfo.getFinished();
int finished = mThreadInfo.getFinished();
connection.setRequestProperty("Range", "bytes="+start+"-"+mThreadInfo.getEnd());
connection.connect();
if (connection.getResponseCode() == HttpStatus.SC_OK || connection.getResponseCode() == HttpStatus.SC_PARTIAL_CONTENT) {
inputStream = connection.getInputStream();
file = FileUtils.getSDCardFile(mFileInfo.getFileName(), "rwd");
file.seek(start);
byte [] buffer = new byte[1024];
int len = 0;
long currentTime = System.currentTimeMillis();
while ((len = inputStream.read(buffer)) != -1) {
file.write(buffer, 0, len);
finished += len;
if (!DownloadService.paused) {
if (System.currentTimeMillis() - currentTime > 500 || finished == mFileInfo.getLength()){
currentTime = System.currentTimeMillis();
Intent intent = new Intent(DownloadService.ACTION_UPDATE_PROGRESS);
intent.putExtra("progress", (int)(finished * 100 /mFileInfo.getLength()));
mContext.sendBroadcast(intent);
}
}
if(DownloadService.paused){
threadDAO.update(mThreadInfo.getUrl(), mThreadInfo.getId(), finished);
}
}
threadDAO.delete(mThreadInfo.getUrl(), mThreadInfo.getId());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
if (file != null) {
try {
file.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}