0

I made an app that, when executed, checks if there is an apk update, by comparing modified dates of the local apk vs the web apk (below is the code). Everything works perfectly.

However, when I go to "Data usage" in the phone, it tells me it used 104MB in the last 3 days, and I opened the app a few times only. It's the first app in the list, even worse than my browser. How could this be?? What is consuming so much data? How can I debug this?

BTW, my phone does not have a chip. I use it as a wifi only device.

This is the code I use to get the modification date:

public static long getfiledate(String url) {
    long size = 0;
    HttpURLConnection c = null;
    try {
        c = (HttpURLConnection) (new URL(url)).openConnection();
        c.setConnectTimeout(timeout);
        c.setReadTimeout(timeout);
        if (c.getResponseCode() == 200) size = c.getLastModified();
        c.disconnect();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return size;
}

UPDATE:

1) 95% of the data usage it is marked as Foreground.

2) I just opened and closed my app, and it 'consumed' 1.5MB!

Luis A. Florit
  • 2,169
  • 1
  • 33
  • 58
  • 1
    Are you checking the modification date using an URL for the .apk? This is totally a guess but maybe HttpURLConnection reads much more data than http header even though you read the header only. – harism Feb 25 '15 at 19:54
  • How often is that executed, and hoe big is the page at the URL? – Gabe Sechan Feb 25 '15 at 19:54
  • @harism: Yes, the url is `http://...../myapp.apk`. The apk file itself has 687K, and the folder containing it just 2.6MB. Even if it reads the whole apk, it would not justify 100MB in 3 days. – Luis A. Florit Feb 25 '15 at 20:18
  • @GabeSechan: Yes, the url is `http://...../myapp.apk`, that has 687K, and the folder containing it just 2.6MB. It is executed on demand only. BTW, 95% of the data usage it is marked as `Foreground`. – Luis A. Florit Feb 25 '15 at 20:21
  • @user1389596: It is of the form `http://mywebsite/folder/myapp.apk` – Luis A. Florit Feb 25 '15 at 20:22
  • I just opened and closed my app, and it consumed 1.5MB! – Luis A. Florit Feb 25 '15 at 20:35
  • Any chance you do the check twice? That would fit well with the data consumption. Can you check the server logs? – Henry Feb 25 '15 at 20:41
  • It almost sounds like openConnection() is downloading the entire apk file. Maybe try a HTTPD HEAD request instead? – Kevin Seifert Feb 25 '15 at 20:51
  • @Henry: I added a `System.out.println("######")` line in the above method, and it appears only once in the Eclipse LogCat after execution. But even if I check twice, why it is retrieving the whole apk?? – Luis A. Florit Feb 25 '15 at 21:36
  • @user1389596: I added `c.setRequestMethod("HEAD")` to the method above, and it still retrieves around 700K. It seems it is downloading the whole file. – Luis A. Florit Feb 25 '15 at 21:48
  • Hmm, you might want to drop down to a raw socket connection, and issue the HTTP directly. That would give you full control. Though the server may also ignore HEAD, and send the whole file? You can test with "telnet HOST 80" and type HTTP directives to confirm. – Kevin Seifert Feb 25 '15 at 21:52
  • Or just have a small text file which has the date/version that you are comparing against to see if the app has be updated. – Morrison Chang Feb 25 '15 at 22:00
  • @user1389596: At least the connection now is cut in half, but it still retrieves the whole file. Maybe I could send an empty file together with the apk, and check ony for it...... – Luis A. Florit Feb 25 '15 at 22:01
  • @MorrisonChang: Yep, that was my idea also. :) Still, I'd like to understand why this is happening. – Luis A. Florit Feb 25 '15 at 22:02
  • The small file trick worked. Still...... why? – Luis A. Florit Feb 25 '15 at 22:14
  • To add to the weirdness: I also check in special circumstances for other 5 text files, some without extension. These sum aprox 200K. Yet, their add only 10K to the download, that should correspond to the headers. So this header request fails only for APK files. Strange! – Luis A. Florit Feb 26 '15 at 03:11

0 Answers0