android-trafficstats

How to get Tethering and Mobile Hotspot data usage in Android using NetworkStatusManager or TrafficStat

梦想的初衷 提交于 2021-01-28 09:14:54
问题 I have an Android application which displaying data usage per app by NetworkStatusManager, but I can't get data usage for Tethering and Mobile Hotspot. How should I do this? 回答1: You need to query by UID and pass in the tethering UID: android.app.usage.NetworkStats.Bucket.UID_TETHERING like so: networkStatsManager.queryDetailsForUid(ConnectivityManager.TYPE_MOBILE, subscriberId, startDate, endDate, android.app.usage.NetworkStats.Bucket.UID_TETHERING); 来源: https://stackoverflow.com/questions

How to get the GPRS Mobile data usage for 1 month?

若如初见. 提交于 2020-01-23 06:41:26
问题 I have searched a lot about this. Found the same code everywhere which solves the purpose partially. As API documentation says, it reset the counter once the device restarts. Sometimes the counter just resets even without the restart. Below is the code float totalRxBytes = (float)TrafficStats.getTotalRxBytes()/(float)1048576; // Received float totalTxBytes = (float)TrafficStats.getTotalTxBytes()/(float)1048576; // Sent float mobRxBytes = (float)TrafficStats.getMobileRxBytes()/(float)1048576;

getUidTxBytes(int uid) always return 0 in android 6.0

不羁岁月 提交于 2019-12-10 12:58:57
问题 I am trying to get network traffic stats of all apps. I just print total network traffic of every application in my device. The code is working fine in android 4.4 and 5.1 devices but in android 6.0 device it always return 0 for all applications. Anyone can please tell me why this happened in android 6.0 devices. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); for(ApplicationInfo app : getPackageManager()

StrictMode java.lang.Throwable: Untagged socket detected

痴心易碎 提交于 2019-12-05 00:47:52
问题 With StrictMode enabled I just started getting this exception: java.lang.Throwable: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage 回答1: There are a couple of ways to handle this exception. First, you have to inspect the stack trace and make sure it is your code reporting the violation. For example, have a look at the following trace. D/StrictMode: StrictMode policy violation: android.os.strictmode.UntaggedSocketViolation: Untagged socket detected;

StrictMode java.lang.Throwable: Untagged socket detected

拥有回忆 提交于 2019-12-03 16:56:21
With StrictMode enabled I just started getting this exception: java.lang.Throwable: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage Java42 There are a couple of ways to handle this exception. First, you have to inspect the stack trace and make sure it is your code reporting the violation. For example, have a look at the following trace. D/StrictMode: StrictMode policy violation: android.os.strictmode.UntaggedSocketViolation: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage at android.os.StrictMode