Network Statistics
The Network Statistics tab displays the network resources used by our application. Let's create a simple example to test this tool. Create a new project and add the following permissions in your manifest
file:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
In the main layout, add a button named, for example, Start Network Connection
. Create a new method to be executed when the button is clicked and add the following code:
public void startNetworkConnection(View v){ new Thread(new Runnable() { public void run() { try{ // Small image TrafficStats.setThreadStatsTag(0x0001); downloadURL("http://goo.gl/iGoYng"); TrafficStats.clearThreadStatsTag(); Thread.sleep(5000); // Medium image TrafficStats.setThreadStatsTag(0x0002); downloadURL("http://goo.gl/eQHDRh"); TrafficStats.clearThreadStatsTag...