问题
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