大家好,又见面了,我是全栈君。
// ---------------------流量统计--------------------------------
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.test.app",
PackageManager.GET_ACTIVITIES);// com.test.app为自己应用的包名
Log.d("!!", "!!" + ai.uid);
long received = TrafficStats.getUidRxBytes(ai.uid);// 获取某个网络UID的接受字节数
long sent = TrafficStats.getUidTxBytes(ai.uid);// 获取某个网络UID的发送字节数
Toast.makeText(mContext, "累计接收数据" + received / 1024 + "KB",
Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "累计发送字节" + sent / 1024 + "KB",
Toast.LENGTH_SHORT).show();
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// -----------------------------------------------------
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115951.html原文链接:https://javaforall.net
