开发者

android downloading apk file from internet results in parsing error

When I try to download file using the following code and run the apk file, it always results in "Parsing Error". I am clueless. Any help is appreciated.

try
                  {
                   URL url  = new URL("http://10.0.0.1/test.apk"); 
                         URLConnection conexion = url.openConnection(); 
 开发者_JS百科                        conexion.connect();
                         int lenghtOfFile = conexion.getContentLength();
                         InputStream is=url.openStream();
                         FileOutputStream fos=new FileOutputStream("/flash/test.apk");
                        byte data[]=new byte[1024];
                        int count=0;
                        long total=0;
                        int progress=0;

                        while ((count=is.read(data)) != -1) 
                         { 
                             total += count; 
                             int progress_temp = (int)total*100/lenghtOfFile; 
                             if(progress_temp%10 == 0 && progress != progress_temp){ 
                                 progress = progress_temp; 
                                 Log.v("APK Download", "total = "+progress);  
                                // Log.v
                             } 
                             fos.write(data, 0, count); 
                         } 

                         is.close(); 
                         fos.close(); 

                         Log.v("APK Download", "Download Done");  



                  }catch (Exception e){}


God Bless! I was so confused and then I looked carefully the file which was uploaded on the webserver that was corrupt. If I upload it through FileZilla it's getting corrupted and if I use cpanel to upload the file, it works great. Thank you God, I am able to move forward in my coding after spending hours with this problem. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜