2015-09-24 70 views
1

我需要監視設備上的所有網絡活動,作爲我的應用程序的一部分,而不是用於調試目的。 This post談論使用TCP轉儲,但一些答案表明這需要root。沒有一個答案能夠真正解釋你如何在應用程序中做到這一點。監控所有網絡活動的Android應用程序如何工作?

我知道在某種程度上可以從應用程序中訪問所有網絡流量,因爲像Network Connections這樣的應用程序可以顯示所有正在訪問的IP地址以及哪些應用程序正在訪問它們。

有誰知道哪些API,權限等我需要使用才能在我的應用程序中獲得這種數據?

+0

如果是爲了調試這取決於您使用的是傳輸數據的內容。 HttpUrlConnection,HttpClient,OkHttp。你通常可以很容易地記錄所有數據。 –

+0

爲了澄清,我想監視設備上的所有網絡活動,而不僅僅是從我的應用程序,我希望它暴露給最終用戶,而不僅僅是調試。我認爲編輯其他用戶造成的不太清楚(儘管它總體上有幫助!) –

回答

1

如果你還在尋找,在包android.net有這個類:

/** 
* 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 { 
+0

@ user3174484你有沒有找到任何方法?我也在努力實現你的目標。 – Kaustubh