Requesting android.permission.READ_NETWORK_USAGE_HISTORY permission

PaulDistonPaulDiston USUniversity ✭✭✭✭
edited July 2017 in Xamarin.Android

I would like to see if I can read the network usage of my application, after some searching it seems that I could use the NetworkStatsService to achieve this, however when I call the Query methods against the NetworkStatsManager instance an exception is raised with the following details :-

Java.Lang.SecurityException: NetworkStats: Neither user 10578 nor current process has android.permission.READ_NETWORK_USAGE_HISTORY.

So I add the android.permission.READ_NETWORK_USAGE_HISTORY permission to the AndroidManifest.xml and also request the permission using Activity.RequestPermissions however I am still presented with the exception.

A couple of questions, from my search I found that the READ_NETWORK_USAGE_HISTORY permission might be protected so I added a protectedLevel attribute, as follows :-

<uses-permission android:name="android.permission.READ_NETWORK_USAGE_HISTORY" android:protectionLevel="signature|privileged"/>

Is this correct?

As this is possibly restricted, is there another way to determine the network usage of my application?

Has anyone been able to use the NetworkStatsManager Query methods successfully?

Sign In or Register to comment.