我试图从android中的设置页面获取3g和wifi使用,无论如何要做到这一点,我可以设置一个意图设置数据使用页面,代码如下;
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings","com.android.settings.Settings$DataUsageSummaryActivity"));
startActivity(intent);
但是有没有办法达到这些意图的组件并从这些组件中获取数据。
Thankss ..
答案 0 :(得分:0)
是的,您可以通过编程方式获取数据使用情况
// 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);
}
试试这种方式 您也可以参考本教程 http://www.techrepublic.com/blog/software-engineer/create-a-network-monitor-using-androids-trafficstats-class/