0

I'm trying to get 3g and wifi usage from Settings page in android, is there anyway to do that, i can set an intent Settings data usage page, code is below;

Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.android.settings","com.android.settings.Settings$DataUsageSummaryActivity"));

    startActivity(intent);

But is there any way to reach these intent's component and to get data from those components.

Thankss..

  • See this: http://stackoverflow.com/questions/17674790/how-do-i-programmatically-show-data-usage-of-all-applications – Sandeep Kharat Apr 03 '17 at 08:44
  • I already checked it, thank you – Maide Nur Oğul Apr 03 '17 at 08:53
  • Possible duplicate of [How can I find the data usage on a per-application basis on Android?](https://stackoverflow.com/questions/11939939/how-can-i-find-the-data-usage-on-a-per-application-basis-on-android) – theJango Jul 28 '18 at 19:47

1 Answers1

0

Yes you can programmatically get the data usage

// Get running processes
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;

  // Get traffic data
  long received = TrafficStats.getUidRxBytes(uid);
  long send   = TrafficStats.getUidTxBytes(uid);
  Log.v("" + uid , "Send :" + send + ", Received :" + received);
}

Try this way And You can also refer this tutorial http://www.techrepublic.com/blog/software-engineer/create-a-network-monitor-using-androids-trafficstats-class/

Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • Actually can't use TrafficStats cause it only collect data since device reboot, so if the device reboots itself in a random time, we lost all data , but i also consider to storage that data regularly in via json or SQLite but in that case it s not possible to get data usage daily or weekly, btw there is also one more class to do that "Network Stats Manager" but it s also non usable for me because i m going to use this app in API 19, but that library requried API:23, so i really dig deep about it, and this s the last solution that i found so i need to get data from settings page. – Maide Nur Oğul Apr 03 '17 at 08:50
  • Thanks for caring. – Maide Nur Oğul Apr 03 '17 at 08:58