how to get data usage from settings in android

﹥>﹥吖頭↗ 提交于 2021-02-08 11:31:26

问题


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..


回答1:


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/



来源:https://stackoverflow.com/questions/43179989/how-to-get-data-usage-from-settings-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!