すべてのアプリケーションのネットワークトラフィック統計情報を取得しようとしています。私はデバイス内のすべてのアプリケーションの合計ネットワークトラフィックを表示します。コードは、アンドロイド4.4および5.1デバイスで正常に動作していますが、アンドロイド6.0デバイスでは、すべてのアプリケーションで常に0が返されます。誰もがなぜこれがアンドロイド6.0デバイスで起こったのか教えてください。ここでgetUidTxBytes(int uid)は、アンドロイド6.0で常に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);
}
}
はdocによると、私の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>
ありがとうございました。 –
問題はアンドロイド6(M)についてです...制限はありません。私はアンドロイド6にいくつかのデバイスを持っていますが、この情報はうまく検索できますが、特定のものはありませんが、この回答によれば、アンドロイド7には制限があります。 –