2

在我的安卓智能手机的设置菜单中,我可以看到当前和过去周期的总数据使用量。我可以以某种方式在我的应用程序中以编程方式检索该信息吗?

提前致谢。

4

1 回答 1

2

您可以使用 android.net.TrafficStats 获取流量详细信息:

例如获取接收到的总字节数:

android.net.TrafficStats.getTotalRxBytes()

如果您想一一获取您的应用程序的发送和接收信息,您可以像这样获得它:

首先通过以下方式获取所有应用程序运行信息:

List<RunningAppProcessInfo>

然后获取您想要的每个应用程序的 UID

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;

  long received = TrafficStats.getUidRxBytes(uid);//received amount of each app
  long send   = TrafficStats.getUidTxBytes(uid);//sent amount of each app
}

让我知道这是你想要的

于 2017-07-04T08:41:06.640 回答