Why is the second, before met once, see http://blog.csdn.net/jason0539/article/details/12222173
For different reasons, record
Public class DownloadTask {/*** @ param path * @ param filePath storage path * @ param progressDialog progress bar * @ return * @ throws Exception */public static File getFile (String path, string filePath, ProgressDialog progressDialog) throws Exception {URL url = new URL (path); HttpURLConnection connection = (HttpURLConnection) url. openConnection (); connection. setConnectTimeout (2000); connection. setRequestMethod ("GET"); if (con Nection. getResponseCode () == 200) {int total = connection. getContentLength (); progressDialog. setMax (total); InputStream is = connection. getInputStream (); // get the socket input stream File = new file (filePath); FileOutputStream fos = new FileOutputStream (File ); // file output stream byte [] buffer = new byte [1024]; int len; int progress = 0; while (len = is. read (buffer ))! =-1) {fos. write (buffer); progress + = len; progressDialog. setProgress (progress);} fos. flush (); is. close (); fos. close (); connection. disconnect (); return file;} return null ;}
This is a class for executing download tasks. It is used to download the updated apk from the server. After the download is successful, it jumps to the installation page, but an error occurs when parsing the package, this error is really a headache and has nothing to do with the code.
Later I found a similar situation http://bbs.csdn.net/topics/380117090? Page = 1 # post-397007671
However, there is no solution. The size of the downloaded apk is slightly different from that in the server folder, so I try to make the size of the byte [] read each time, that is
byte[] buffer = new byte[1024];
In this line of code, 1024 is changed to 128 and 64, and the result is OK.
Unexpected receipt. If you encounter a similar problem, try it. good luck.
Author: jason0539
Weibo: http://weibo.com/2553717707
Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)