1

I need to monitor all network activity on the device as part of my application rather than for debugging purposes. This post talks about using TCP dump, but some answers suggest this requires root. None of the answers really explain how you would do it within an app.

I know it is somehow possible to access all network traffic from within an app, because apps like Network Connections can display all IP addresses that are being accessed, and also which apps are accessing them.

Does anyone know which APIs, permissions, etc. I would need to use in order to get this kind of data in my app?

Community
  • 1
  • 1
Patrick Grayson
  • 548
  • 3
  • 17
  • If it's for debugging it depends what you're using to transport the data. HttpUrlConnection, HttpClient, OkHttp. You can usually log all data going through these pretty easily. – a person Sep 24 '15 at 22:05
  • To clarify, I want to monitor all network activity on the device, not just from my application, and I want it to be exposed to the end user, not just for debugging. I think the edit another user made caused that to be less clear (though it was overall helpful!) – Patrick Grayson Sep 25 '15 at 14:51

1 Answers1

1

If you're still looking, in the package android.net there's this class:

/**
 * Collection of historical network statistics, recorded into equally-sized
 * "buckets" in time. Internally it stores data in {@code long} series for more
 * efficient persistence.
 * <p>
 * Each bucket is defined by a {@link #bucketStart} timestamp, and lasts for
 * {@link #bucketDuration}. Internally assumes that {@link #bucketStart} is
 * sorted at all times.
 *
 * @hide
 */
public class NetworkStatsHistory implements Parcelable {
a person
  • 986
  • 6
  • 13