Tuesday, January 28, 2014
A puzzled about downloading files
android by HttpURLConnection download files exactly apk files on the file size and the server to get the download is complete, but the apk file with the server files do not get the same, suggesting that it is illegal to install apk, it was not proven legitimate apk, But wonder children are exactly the same size ah, is it in the download process where a subtle difference? (A total of 45 points got left,,,,)
protected SizeData doInBackground (String. .. params) {
Log.e (TAG, "doInBackground");
int totalLength = urlConn.getContentLength ();
onStart (Math.max (0, totalLength), startLocation) ;/ / notice, ready to start
SizeData result = null;
int downloadSize = 0;
try {
inputStream = urlConn.getInputStream ();
} Catch (IOException e1) {
e1.printStackTrace ();
result = SizeData.createErrorData (downloadSize);
}
if (inputStream! = null) {
try {
outputStream = getFileStream (tempPath);
} Catch (IOException e1) {
e1.printStackTrace ();
result = SizeData.createErrorData (downloadSize);
}
byte [] bufByte = new byte [128];
int receiveCount = noticeBitSize / 128;
int curtCount = 0;
try {
while (alive) {
curtCount + +;
int count = inputStream.read (bufByte);
if (count == -1) {
Log.e (TAG, tempPath + "Download Complete");
onReceiveSuccess (downloadSize);
curtCount = 0;
result = SizeData.createRightData (downloadSize);
break;
}
if (count == 0) {
result = SizeData.createErrorData (downloadSize);
break;
}
outputStream.write (bufByte, 0, count);
downloadSize + = count;
if (curtCount> = receiveCount) {
onReceiveSuccess (downloadSize);
curtCount = 0;
}
}
} Catch (IOException e) {
e.printStackTrace ();
result = SizeData.createErrorData (downloadSize);
}
if (! alive) {
result = SizeData.createOtherData (downloadSize);
}
try {
outputStream.flush ();
} Catch (IOException e) {
e.printStackTrace ();
} Finally {
try {
outputStream.close ();
} Catch (IOException e) {
e.printStackTrace ();
}
}
}
return result;
}
Reply:
You can save the file on the server MD5 code, after downloading the file server to complete the calculation of MD5 and MD5 file in the terminal for comparison to determine whether to download the file is complete. Download the file on your code does not look, GOOGLE what many ready-made code
Reply:
MD5 checksum is currently no way to use and is currently judged by the size of the file is downloaded and getContentLength () Comparison
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment