1 android通过架构流量统计TrafficStats类可以直接获得

    获得总流量受理TrafficStats.getTotalRxBytes(),

    获得总传出流量TrafficStats.getTotalTxBytes());

   获取不包括WIFI的手机GPRS接收量TrafficStats.getMobileRxBytes());

   获取不包括Wifi的手机GPRS发送量TrafficStats.getMobileTxBytes());



    统计某一个进程的总接收量TrafficStats.getUidRxBytes(Uid));

    统计某一个进程的总发送量TrafficStats.getUidTxBytes(Uid));



这些获取的流量都是从一次开机到读取时刻的统计量。

所以。统计某一个程序的流量统计的时候,一定要注意开关机。和本次开机后是第几次启动本程序。



2 android的TrafficStats类

前四个读取的/proc/net/dev里面的数据

后面的两个接口对某一个进程的流量统计的是/proc/uid_stat/*** 接口里面的节点 数据



package cn.sunzn.trafficmanger;

import android.app.Activity;

import android.net.TrafficStats;

import android.os.Bundle;

import android.view.Menu;

public class MainActivity extends Activity {

   public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

       /** 获取手机通过 2G/3G 接收的字节流量总数 */

       TrafficStats.getMobileRxBytes();

       /** 获取手机通过 2G/3G 接收的数据包总数 */

       TrafficStats.getMobileRxPackets();

       /** 获取手机通过 2G/3G 发出的字节流量总数 */

       TrafficStats.getMobileTxBytes();

       /** 获取手机通过 2G/3G 发出的数据包总数 */

       TrafficStats.getMobileTxPackets();

       /** 获取手机通过全部网络方式接收的字节流量总数(包含 wifi) */

       TrafficStats.getTotalRxBytes();

       /** 获取手机通过全部网络方式接收的数据包总数(包含 wifi) */

       TrafficStats.getTotalRxPackets();

       /** 获取手机通过全部网络方式发送的字节流量总数(包含 wifi) */

       TrafficStats.getTotalTxBytes();

       /** 获取手机通过全部网络方式发送的数据包总数(包含 wifi) */

       TrafficStats.getTotalTxPackets();

       /** 获取手机指定 UID 相应的应程序用通过全部网络方式接收的字节流量总数(包含 wifi) */

       TrafficStats.getUidRxBytes(uid);

       /** 获取手机指定 UID 相应的应用程序通过全部网络方式发送的字节流量总数(包含 wifi) */

       TrafficStats.getUidTxBytes(uid);

   }

   public boolean onCreateOptionsMenu(Menu menu) {

       getMenuInflater().inflate(R.menu.activity_main, menu);

       return true;

   }

}



Android OS下有几个应用是集体的,包含(Android系统、设置存储、设置、系统用户界面、miui)

OS里面的各个模块的流量统计都算到OS 1000流程,假设一个模块不能揪出问题,您可以创建界面计算。

版权声明:本文博主原创文章,博客,未经同意不得转载。

android 流量统计的更多相关文章

  1. Android流量统计TrafficStats类

    对于Android流量统计来说在2.2版中新加入了TrafficStats类可以轻松获取,其实本身TrafficStats类也是读取Linux提供的文件对象系统类型的文本进行解析. android.n ...

  2. android流量统计

    研究过一段时间的android流量统计发个自己的总结帖 1 android有一个TrafficStats类可以直接获取 总接受流量TrafficStats.getTotalRxBytes(), 总发送 ...

  3. android app 流量统计

    https://blog.csdn.net/yzy9508/article/details/48300265 | android 数据流量统计 - CSDN博客https://blog.csdn.ne ...

  4. Android学习笔记_64_手机安全卫士知识点归纳(4) 流量统计 Log管理 混淆打包 加入广告 自动化测试 bug管理

    android 其实就是linux 上面包装了一个java的框架. linux 系统下 所有的硬件,设备(网卡,显卡等) 都是以文件的方式来表示. 文件里面包含的有很多设备的状态信息. 所有的流量相关 ...

  5. Android中进行流量统计

    // ---------------------流量统计-------------------------------- try { PackageManager pm = getPackageMan ...

  6. Android开发——流量统计

    1. 获取应用UID 在设备的proc目录下我们可以看到一些比较熟悉的目录/文件,比如data,system,cpuinfo(获取CPU信息)等,其中uid_stat的各个以应用Uid命名的目录下,便 ...

  7. 安卓App流量统计

    http://keepcleargas.bitbucket.org/2013/10/12/android-App-Traffic.html 安卓App流量统计 12 OCT 2013 android流 ...

  8. [Android Traffic] android 流量计算方法

    android流量简介 流量统计文件:路径/proc/net/dev 打开文件,其中 lo 为本地流量, rmnet0 为3g/2g流量, wlan0 为无线流量. 在/sys/class/net/下 ...

  9. iOS 网络流量统计

    在开发中,有时候需要获取流量统计信息.研究发现:通过函数getifaddrs来得到系统网络接口的信息,网络接口的信息,包含在if_data字段中, 有很多信息, 但我现在只关心ifi_ibytes,  ...

随机推荐

  1. 51NOD——N 1107 斜率小于0的连线数量

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 ...

  2. 洛谷——P1774 最接近神的人_NOI导刊2010提高(02)

    https://www.luogu.org/problem/show?pid=1774 题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古 ...

  3. [React Intl] Install and Configure the Entry Point of react-intl

    We’ll install react-intl, then add it to the mounting point of our React app. Then, we’ll use react- ...

  4. malloc和realloc

    malloc函数: extern void *malloc(unsigned int num_bytes); malloc 向系统申请分配指定size个字节的内存空间. 如果分配成功则返回指向被分配内 ...

  5. VS无法访问IIS元数据库 您没有足够的特权访问计算机上的IIS网站

    进入windows\regedit.exe下的HKEY_CRRENT_USER\Software\Microsoft\Windows\CurrentVersion\Exploer\User Shell ...

  6. [Angular2 Form] Model Driven Form Custom Validator

    In this tutorial we are going to learn how simple it is to create custom form field driven validator ...

  7. ImageButton按压效果失效

    LinearLayout中ImageButton的按压效果不起作用,如图 布局如下: <LinearLayout android:id="@id/ll_add_reply_face&q ...

  8. 读Effective Objective-C [提高OC代码质量总结笔记第一篇:熟悉OC]

    一.OC特性 OC 为 C 语言添加了面向对象特性,是其超集; OC 使用动态绑定的消息结构,也就是,在运行时才会检查对象类型; 接收一条消息后,究竟应执行何种代码,由运行期环境来决定,而非 编译器; ...

  9. Visual Studio 项目目录下的bin目录和 obj目录

    一.Bin目录 Visual Studio 编译时,在bin 目录下有debug 和 release 目录. 1.Debug: 通常称为调试版本,它包含调试信息,所以要比Release 版本大很多(可 ...

  10. [Http] Understand what an HTTP Request is

    Let's look at several HTTP requests to learn the basic structure of these messages, and how the vari ...