I try get the total Tx and Tr Bytes per installed apps, but always returns -1, except in my app. This is my code:
val pm = context.packageManager
val apps = HashMap<String, Long>()
for( app in pm.getInstalledApplications(0) ) {
Log.i(TAG, "app.packageName=${app.packageName} TrafficStats.getUidTxBytes(app.uid)=${TrafficStats.getUidTxBytes(app.uid)} TrafficStats.getUidRxBytes(app.uid)=${TrafficStats.getUidRxBytes(app.uid)}")
apps.put(app.packageName, TrafficStats.getUidRxBytes(app.uid)+TrafficStats.getUidTxBytes(app.uid))
}
As per documentation:
When getting return values you don't expect, always check the most recent documentation first.