Android error parsing package error (2)

Source: Internet
Author: User

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)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.