gpt4 book ai didi

android - getUidRxBytes() 和 getUidTxBytes() 在 Android 4.3 中总是返回 0

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:54 27 4
gpt4 key购买 nike

我觉得我现在正在服用疯狂的药丸。我的应用程序的特定部分几天来一直运行良好,今天它停止工作,我不明白为什么。我的这部分代码用于输出自启动以来每个特定应用程序已发送和接收的总数据。现在,值始终显示为 0。

一些可能影响也可能不影响的事情:

1.) 我的 Nexus 4 今天刚更新到 Android 4.3,但我怀疑这是个问题,因为我更新后它运行良好。

2.) 随着 Android API 18 的更新,Traffic Stats API 中的一些方法现在已被弃用,但这些方法我什至没有使用过,所以这应该没有效果。 http://developer.android.com/reference/android/net/TrafficStats.html

非常感谢所有帮助。

PackageManager packageManager=this.getPackageManager();
List<ApplicationInfo> appList=packageManager.getInstalledApplications(0);

for (ApplicationInfo appInfo : appList) {
String appLabel = (String) packageManager.getApplicationLabel(appInfo);
int uid = appInfo.uid;
Log.d("data", String.valueOf(TrafficStats.getUidRxBytes(uid) + TrafficStats.getUidTxBytes(uid)));

更新 [2014 年 1 月 23 日]: 在运行 Android 4.4.2 的 Nexus 4 上测试 getUidRxBytes() 和 getUidTxBytes() 显示值不再为 0,但报告正确统计数据。

最佳答案

我已将此问题报告给 AOSP 问题跟踪器:here

我还为我粘贴在下面的问题创建了一个替代解决方案:

private Long getTotalBytesManual(int localUid){

File dir = new File("/proc/uid_stat/");
String[] children = dir.list();
if(!Arrays.asList(children).contains(String.valueOf(localUid))){
return 0L;
}
File uidFileDir = new File("/proc/uid_stat/"+String.valueOf(localUid));
File uidActualFileReceived = new File(uidFileDir,"tcp_rcv");
File uidActualFileSent = new File(uidFileDir,"tcp_snd");

String textReceived = "0";
String textSent = "0";

try {
BufferedReader brReceived = new BufferedReader(new FileReader(uidActualFileReceived));
BufferedReader brSent = new BufferedReader(new FileReader(uidActualFileSent));
String receivedLine;
String sentLine;

if ((receivedLine = brReceived.readLine()) != null) {
textReceived = receivedLine;
}
if ((sentLine = brSent.readLine()) != null) {
textSent = sentLine;
}

}
catch (IOException e) {

}
return Long.valueOf(textReceived).longValue() + Long.valueOf(textReceived).longValue();

}

关于android - getUidRxBytes() 和 getUidTxBytes() 在 Android 4.3 中总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17894966/

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