手机总流量统计
2016-04-17 16:37
239 查看
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import android.content.Context; import android.text.format.Formatter; /** * 流量统计的业务类 * @author Administrator * */ public class ConnectivityEngine { /** * @return * 接收的流量信息(格式化的如:33MB) */ public static String getReceive(int uid,Context context){ String res = null; //读取流量信息文件 /proc/uid_stat/uid/tcp_rcv String path = "/proc/uid_stat/" + uid + "/tcp_rcv"; try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path))); String line = reader.readLine(); long size = Long.parseLong(line); res = Formatter.formatFileSize(context, size); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; } /** * @return * 发送的流量信息(格式化的如:33MB) */ public static String getSend(int uid,Context context){ String res = null; //读取流量信息文件 /proc/uid_stat/uid/tcp_snd String path = "/proc/uid_stat/" + uid + "/tcp_snd"; try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path))); String line = reader.readLine(); long size = Long.parseLong(line); res = Formatter.formatFileSize(context, size); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; } }
相关文章推荐
- Little-Endian or Bigger-Endian?
- Python 集合(set)类型的操作
- Learning Scrapy笔记(六)- Scrapy处理JSON API和AJAX页面
- PHP实现当前文件夹下所有文件和文件夹的遍历
- [HDOJ1171]Big Event in HDU(01背包)
- zoj 3903 Ant【推公式+逆元】
- javascript中textContent与innerText的异同分析
- 自定义多状态高仿应用下载百分数view
- web基础
- Android音频开发(6):使用 OpenSL ES API(上)
- 第五种项目四-长方柱类
- 水电费
- new、delete、malloc、free
- microsoft project 添加空行 空白行 空白任务
- Activity生命周期
- spring基础知识详解
- Windows Eclipse 调试 HBase
- POJ 3069Saruman's Army
- Android之Wifi开发
- MySql中外键约束