On some devices, the file is loaded in five seconds, on others (Samsung J5 - Android 5.1, Genymotion Google Nexus S - Android 4.1.1) about a minute. What can this happen? Internet is normal on smartphones. Code:

public static boolean loadFile(Context context, File outFile) { int count; AppLog.d("loadFile, start = " + DateFormat.getDateTimeInstance().format(new Date())); try { CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL url = new URL(url); URLConnection connection = url.openConnection(); connection.setConnectTimeout(ServiceClient.TIME_OUT); connection.connect(); // download the file InputStream input = new BufferedInputStream(url.openStream(), 8192); OutputStream output = new FileOutputStream(outFile); byte data[] = new byte[BUFFER_LENGTH]; while ((count = input.read(data)) != -1) { output.write(data, 0, count); } output.flush(); output.close(); input.close(); AppLog.d("loadFile, finish = " + DateFormat.getDateTimeInstance().format(new Date())); return true; } catch (Exception e) { e.printStackTrace(); return false; } } 

Long loading occurs directly in the line:

 output.write(data, 0, count); 
  • one
    Make logging when it enters the method, after what time the connection is opened, after how long the download starts, when it ends. So that it is not easy for how many to find out, but at what stage it stops. - VAndrJ
  • @VAndrJ added a question - iamtihonov

1 answer 1

Everything is very trite.

Different phones have a different memory card (or built-in memory). And the speed can vary up to a dozen times. Moreover, if the phone's memory is “crammed” and the card is “living out its days”, the write speed can be very slow. Also, some manufacturers save and put cheap (and as a result, slow) memory. Try potestit write speed, for example .

Secondly, different phones have different radio modules. And as a result, the download speed is different. For example, some WiFi can work poorly with certain versions of routers (I personally came across this). For example, Samsung S6 on TP-link downloaded files and surfed the Internet very slowly. And the Nexus lying next to it squeezed the entire channel to the maximum. Replacing the router with asus corrected the situation. A router for transmission can use different signal coding, but it can give a different speed.

Thirdly, different phones have an antenna placed differently. There is also such a thing as signal interference. And the phones lying half a meter from each other will live in different conditions. To read .

Fourth. Some service may be running on the phone, for example, a classic media server that scans files. It is clear that this can greatly reduce the speed of the write speed.

Reading the question more carefully, I replaced the word "Genymotion" - that is, the emulator. I understand correctly that you are comparing the download speed for a real device and an emulator? The emulator is certainly good to use for testing the code, but if the program does not work on a real device, then no one needs it (except for a small group of perverts who use emulators not for development).