gpt4 book ai didi

android - 如何以编程方式获取 Android 设备的总数据使用量?

转载 作者:行者123 更新时间:2023-12-04 23:58:12 25 4
gpt4 key购买 nike

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

提前致谢。

最佳答案

您可以使用 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
}

告诉我这就是你想要的

关于android - 如何以编程方式获取 Android 设备的总数据使用量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44900721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com