Book Image

Testing and securing android studio applications

Book Image

Testing and securing android studio applications

Overview of this book

Table of Contents (18 chapters)
Testing and Securing Android Studio Applications
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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...