Android Question Issue downloading files with HttpUtils2 on Mobile Data

Discussion in 'Android Questions' started by dieterp, Mar 12, 2015.

  1. dieterp

    dieterp Active Member Licensed User


    My app uses HttpUtils2 to download images from a server. The files are not big, and I can have up to 20-30 files download at a time. The app will only download a file once a success message has been received in JobDone that the previous file was successfully downloaded.

    When I run this process connected to Wifi the files will download every time without fail. When I use Mobile Data though (Wifi disconnected), at some point one of the files will 'hang' and I'll eventually get the timeout message of 'SocketTimeOutException'. This happens almost every time on Mobile Data. At one point I restarted my device and it worked, but subsequently it has started happening again and even a restart doesn't fix it.

    What are my options here? The mobile Data has a 4G connection so speed isn't an issue. The Wifi has a 3G connection, so even when I force my device to use 3G as Mobile Data, I still get the issue.
  2. KMatle

    KMatle Expert Licensed User

    Which phone do you have and which ROM (custom or other like Cyanogen)? What about other downloads (f.e. via browser). Does this work?

    I have some apps doing the same. No problem (file size is about 150-200 KB).

    As a workarround you can increase the timeout with:

    Job.GetRequest.Timeout = 
  3. dieterp

    dieterp Active Member Licensed User

    I have a Samsung Galaxy S5, so there shouldn't be any issues with the phone specs. The timeout is set to 40 seconds which should be more than enough time, yet the issue still persists.

    I don't download many things from any servers so it's hard to say what happens on other downloads, but I can browse the internet with no problems, and generally there aren't problems when I download the actual app from the same server when I'm doing updates.
  4. KMatle

    KMatle Expert Licensed User

    S5. Ok. That's not the problem. If the 3G/4G connection is stable and at high speed it must be something else. What exactly do you download? Pictures? And what do you do with it? I'm thinking about out of memory problems...
  5. dieterp

    dieterp Active Member Licensed User

    I download small images that are about 20kb in size and I save them into to the DirDefaultExternal folder of the device. I doubt it could be memory problems as it works fine on Wifi. It must have something to do with the Mobile Data connection. I'm going to try test on different devices. If my device is the only one experiencing the issue on Mobile Data then maybe something is wrong with my device. Will keep you posted!
  6. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to implement a "retry" mechanism? Use a timer to wait a few seconds after the error occurs and try to download again.
  7. KMatle

    KMatle Expert Licensed User

    Are you able to try it on a friends phone?
  8. dieterp

    dieterp Active Member Licensed User

    I'll try that Erel. I'll also build something in to check that the file has finished copying into the DirDefaultExternal folder before trying to download the next file. I did also find that in Debug mode, when I stop and step through each download I have no problems, if that sheds any light on the situation?

    I have tried it on a friends S3 and it works fine on mobile data, so it may be something to do with my phone then. I'd need to test on more devices though.
    KMatle likes this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    No need. If File.Copy didn't raise an error then the file was copied successfully.

    Not sure whether it is related.
    dieterp likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice