Advertisement
Guest User

doInBackground

a guest
Mar 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. protected String doInBackground(String... aurl) {
  2.             int count;
  3.  
  4.         try {
  5.  
  6.         URL url2 = new URL(aurl[0]);
  7.         URLConnection conexion = url2.openConnection();
  8.         conexion.connect();
  9.  
  10.         int lenghtOfFile = conexion.getContentLength();
  11.         Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
  12.        
  13.         //String version = Build.USER;
  14.  
  15.         InputStream input = new BufferedInputStream(url2.openStream());
  16.         OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/MIUIPolska_" + device + "_" + upversion + "-" + realbase + ".zip");
  17.  
  18.         byte data[] = new byte[1024];
  19.  
  20.         long total = 0;
  21.  
  22.             while (((count = input.read(data)) != -1) && (this.isCancelled()==false)){
  23.                 total += count;
  24.                 publishProgress(""+(int)((total*100)/lenghtOfFile));
  25.                 output.write(data, 0, count);
  26.             }
  27.             //String mixtapefilename = "miuipl_hotfix.zip";
  28.             //String zipname = mixtapefilename;
  29.             //String path = Environment.getExternalStorageDirectory() + "/";              
  30.             //unpackZip(path, zipname);
  31.            
  32.             output.flush();
  33.             output.close();
  34.             input.close();
  35.         } catch (Exception e) {}
  36.         return null;
  37.  
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement