Note that there are some explanatory texts on larger screens.

plurals
  1. POFind how much network traffic other Android apps generate
    primarykey
    data
    text
    <p>I am trying to make a background service which should measure traffic usage of various applications so as to be able to show to the user which apps consume most data traffic.</p> <p>I found that Spare Parts app does exactly that, but after installing it on a 1.6 Dell Streak device I always get "No battery usage data available" for "Network usage". Does this function at all work in Spare Parts? Also, I couldn't find a working source code for Spare Parts. </p> <p><a href="https://android.googlesource.com/platform/development/+/froyo-release/apps/SpareParts" rel="nofollow noreferrer">https://android.googlesource.com/platform/development/+/froyo-release/apps/SpareParts</a><br> looks to be outdated or incomplete. (?)</p> <p>But Spare Parts seems to measure e.g. CPU usage per app. How does it do that on an unrooted phone? </p> <p>My general idea of how traffic per app could be measured is to regularly check the </p> <p><code>"sys/class/net/" + sWiFiInterface + "/statistics/rx_bytes"</code></p> <p><code>"sys/class/net/" + sWiFiInterface + "/statistics/tx_bytes"</code></p> <p><code>"sys/class/net/" + sMobileInterface + "/statistics/rx_bytes"</code></p> <p><code>"sys/class/net/" + sMobileInterface + "/statistics/tx_bytes"</code></p> <p>files and to see which app currently has focus and thus most likely to cause the generated network traffic.</p> <p>Unfortunately I can't find how to get the app currently having focus.</p> <p>I found this:</p> <p><a href="https://stackoverflow.com/questions/1558750/android-how-to-get-information-on-which-activity-is-currently-showing-in-forego">Android, how to get information on which activity is currently showing (in foregorund)?</a></p> <p>but seems it's about testing, not just a 3d party service running on non-rooted Android device.</p> <p>We can get what activities are running with <code>ActivityManager.getCurrentTasks()</code>, but any of them can be the one with focus. It seems like the Android architects explicitly don't want 3d party apps to know what app has focus, because of security concerns </p> <p>(see <a href="http://android.bigresource.com/Track/android-zb2mhvZX4/" rel="nofollow noreferrer">http://android.bigresource.com/Track/android-zb2mhvZX4/</a>). </p> <p>Is there a way around this?</p> <p>Also, if I want to not only detect which activities eat up traffic but also what services, I can get all currently running services with <code>ActivityManager.getCurrentSerives()</code> and even see for each one if it's in foreground mode (unlike to be thrown out if Android needs resources). But this again doesn't bring me any far.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload