In the settings menu on my android smartphone, I can see the total data usage of the current and past cycles. Can I somehow retrieve that information programmatically in my app?
Thanks in advance.
In the settings menu on my android smartphone, I can see the total data usage of the current and past cycles. Can I somehow retrieve that information programmatically in my app?
Thanks in advance.
You can use android.net.TrafficStats to get traffic details:
for example to get Total bytes received:
android.net.TrafficStats.getTotalRxBytes()
and if you want to get send and received info of your apps one by one you can get it like this:
first get all apps running info by this:
List<RunningAppProcessInfo>
then get UID of each app you want
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningApps = manager.getRunningAppProcesses();
for (RunningAppProcessInfo runningApp : runningApps) {
// Get UID of the selected process
int uid = ((RunningAppProcessInfo)getListAdapter().getItem(position)).uid;
long received = TrafficStats.getUidRxBytes(uid);//received amount of each app
long send = TrafficStats.getUidTxBytes(uid);//sent amount of each app
}
let me know is this what you want