- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试获取所有应用程序的网络流量统计信息。我只是打印设备中每个应用程序的总网络流量。该代码在 android 4.4 和 5.1 设备中运行良好,但在 android 6.0 设备中它始终为所有应用程序返回 0。任何人都可以告诉我为什么这发生在 android 6.0 设备上。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(ApplicationInfo app : getPackageManager().getInstalledApplications(0)){
long tx = TrafficStats.getUidTxBytes(app.uid);
long rx = TrafficStats.getUidRxBytes(app.uid);
long total = tx + rx;
Log.e("total data of ", app.packageName + " = " + total);
}
}
这是我的 AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mts.trafficstatsdemo">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
最佳答案
根据 doc :
Starting in N this will only report traffic statistics for the calling UID. It will return UNSUPPORTED for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, use NetworkStatsManager.
关于android - getUidTxBytes(int uid) 在 android 6.0 中总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41406551/
我正在尝试在我的代码中获取流量统计信息。但是当我使用 TrafficStats.getUidTxBytes(uid) 它总是返回-1,即 TrafficStats.UNSUPPORTED 我不确定如何
我正在尝试弄清楚如何检索按应用分割的单独移动(蜂窝/3G/4G)数据使用情况和单独的 WIFI 使用情况。我看到 android.trafficstats 有 getUidRxBytes/getUid
我正在尝试获取所有应用程序的网络流量统计信息。我只是打印设备中每个应用程序的总网络流量。该代码在 android 4.4 和 5.1 设备中运行良好,但在 android 6.0 设备中它始终为所有应
我觉得我现在正在服用疯狂的药丸。我的应用程序的特定部分几天来一直运行良好,今天它停止工作,我不明白为什么。我的这部分代码用于输出自启动以来每个特定应用程序已发送和接收的总数据。现在,值始终显示为 0。
我是一名优秀的程序员,十分优秀!