如何从Android中的设置获取数据使用情况 [英] how to get data usage from settings in android
问题描述
我正在尝试从android的设置"页面获取3g和wifi的使用情况,无论如何,我可以设置一个意图设置数据使用情况页面,代码如下;
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.
谢谢..
推荐答案
是的,您可以通过编程方式获取数据使用量
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);
}
尝试这种方式您也可以参考本教程 http://www.techrepublic.com/blog/software-engineer/create-a-network-monitor-using-androids-trafficstats-class/
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/
这篇关于如何从Android中的设置获取数据使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!