Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Testing and securing android studio applications

You're reading from  Testing and securing android studio applications

Product type Book
Published in Aug 2014
Publisher Packt
ISBN-13 9781783988808
Pages 162 pages
Edition 1st Edition
Languages

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}