Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  2. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
  3.  
  4. private void downloadData(){
  5. try{
  6. Log.v(TAG, "downloading data");
  7.  
  8. URL url = new URL("http://10.0.2.2/1.zip");
  9. URLConnection connection = url.openConnection();
  10. connection.connect();
  11.  
  12. int lenghtOfFile = connection.getContentLength();
  13.  
  14. Log.v(TAG, "lenghtOfFile = "+lenghtOfFile);
  15.  
  16. InputStream is = url.openStream();
  17.  
  18. File testDirectory = new File(Environment.getExternalStorageDirectory()+"/testDirectory/");
  19. if(!testDirectory.exists()){
  20. testDirectory.mkdir();
  21. }
  22.  
  23. FileOutputStream fos = new FileOutputStream(testDirectory+"/files.zip");
  24.  
  25. byte data[] = new byte[1024];
  26.  
  27. int count = 0;
  28. long total = 0;
  29. int progress = 0;
  30.  
  31. while ((count=is.read(data)) != -1)
  32. {
  33. total += count;
  34. int progress_temp = (int)total*100/lenghtOfFile;
  35. if(progress_temp%10 == 0 && progress != progress_temp){
  36. progress = progress_temp;
  37. Log.v(TAG, "total = "+progress);
  38. }
  39. fos.write(data, 0, count);
  40. }
  41.  
  42. is.close();
  43. fos.close();
  44.  
  45. Log.v(TAG, "downloading finished");
  46.  
  47. }catch(Exception e){
  48. Log.v(TAG, "exception in downloadData");
  49. e.printStackTrace();
  50. }
  51.  
  52. }
  53.  
  54. 00:00 It starts downloading:
  55. V/iPhoto ( 853): downloading data
  56. V/iPhoto ( 853): lenghtOfFile = 7732809
  57. V/iPhoto ( 853): total = 10
  58. V/iPhoto ( 853): total = 20
  59. V/iPhoto ( 853): total = 30
  60. V/iPhoto ( 853): total = 40
  61. V/iPhoto ( 853): total = 50 (round 00:05)
  62. -> Here it stops and the DDMS disconnects the device immediately
  63.  
  64. 03:40 It finish the download (not always) and the device reboots on its own:
  65. I/Process ( 595): Sending signal. PID: 595 SIG: 3
  66. I/dalvikvm( 595): threadid=7: reacting to signal 3
  67. D/dalvikvm( 722): GC freed 2193 objects / 135808 bytes in 176 sec
  68. V/iPhoto ( 853): total = 60
  69. I/dalvikvm( 595): Wrote stack trace to '/data/anr/traces.txt'
  70. I/ActivityManager( 595): Process com.google.android.apps.maps:FriendService (pid 778) has died.
  71. I/ActivityManager( 595): Process com.android.mms (pid 732) has died.
  72. V/iPhoto ( 853): total = 70
  73. V/iPhoto ( 853): total = 80
  74. V/iPhoto ( 853): total = 90
  75. V/iPhoto ( 853): total = 100
  76. V/iPhoto ( 853): downloading finished
  77. V/iPhoto ( 853): thread finish loading
  78. I/Process ( 595): Sending signal. PID: 595 SIG: 9
  79. I/ActivityThread( 757): Removing dead content provider: settings
  80. I/ActivityThread( 748): Removing dead content provider: settings
  81. I/ActivityThread( 722): Removing dead content provider: settings
  82. I/ActivityThread( 700): Removing dead content provider: settings
  83. I/ServiceManager( 549): service 'package' died
  84. ... services dying...
  85. I/ServiceManager( 549): service 'wifi' died
  86. E/installd( 557): eof
  87. E/installd( 557): failed to read size
  88. I/installd( 557): closing connection
  89. D/qemud ( 560): fdhandler_event: disconnect on fd 11
  90. D/qemud ( 560): fdhandler_event: disconnect on fd 12
  91. E/vold ( 550): Framework disconnected
  92. I/Zygote ( 554): Exit zygote because system server (595) has terminated
  93. I/ServiceManager( 549): service 'simphonebook' died
  94. I/ServiceManager( 549): service 'isms' died
  95. I/ServiceManager( 549): service 'iphonesubinfo' died
  96. I/ServiceManager( 549): service 'phone' died
  97. D/AndroidRuntime( 949):
  98. D/AndroidRuntime( 949): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
  99. ... and starting ...
  100.  
  101. // flushing output
  102. fos.flush();
  103. // closing streams
  104. fos.close();
  105. is.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement