Guest User

Untitled

a guest
Feb 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. URL url = new URL(urlToDownload);
  2. URLConnection connection = url.openConnection();
  3. connection.connect();
  4. // this will be useful so that you can show a typical 0-100% progress bar
  5. int fileLength = connection.getContentLength();
  6.  
  7. // download the file
  8. InputStream input = new BufferedInputStream(connection.getInputStream());
  9. OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk");
  10.  
  11. byte data[] = new byte[1024];
  12. long total = 0;
  13. int count;
  14. while ((count = input.read(data)) != -1) {
  15. total += count;
  16. // publishing the progress....
  17. Bundle resultData = new Bundle();
  18. resultData.putInt("progress" ,(int) (total * 100 / fileLength));
  19. receiver.send(UPDATE_PROGRESS, resultData);
  20. output.write(data, 0, count);
  21. }
  22.  
  23. output.flush();
  24. output.close();
  25. input.close();
  26.  
  27. private void srcDirs(String path)
  28.  
  29. {
  30. File directory = new File(path);
  31. File [] DirList = directory.listFiles();
  32.  
  33. AssetManager assetManager = this.getAssets();
  34. InputStream in = null;
  35. OutputStream out = null;
  36.  
  37. for(File dirname: DirList)
  38. {
  39. String fullPath = extStorageDirectory + "/Pictures/" + dirname.getName(); // destination
  40. if(dirname.isFile())
  41. {
  42. try{
  43. in = assetManager.open(path);
  44. String newFileName = fullPath + "/" + dirname ;
  45. out = new FileOutputStream(newFileName);
  46.  
  47. byte[] buffer = new byte[1024];
  48. int read;
  49. while ((read = in.read(buffer)) != -1) {
  50. out.write(buffer, 0, read);
  51. }
  52. in.close();
  53. in = null;
  54. out.flush();
  55. out.close();
  56. out = null;
  57.  
  58.  
  59. }
  60. catch (Exception e) {
  61. Log.e("tag", e.getMessage());
  62. }
  63.  
  64. }
  65. else if(dirname.isDirectory())
  66. {
  67. File desdir = new File(fullPath);
  68.  
  69. if(!desdir.exists())
  70. {
  71. desdir.mkdirs();
  72.  
  73. }
  74.  
  75. }
  76.  
  77. }
  78.  
  79. <uses-permission
  80. android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  81. <uses-permission android:name="android.permission.INTERNET"/>
  82. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  83. <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  84.  
  85. URL url = new URL("10.../.././CPI"); // hypothetically
  86. URLConnection connection = url.openConnection();
Add Comment
Please, Sign In to add comment