手机总流量统计
发布日期:2021-06-30 18:39:34
浏览次数:3
分类:技术文章
本文共 1864 字,大约阅读时间需要 6 分钟。
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; }}
转载地址:https://linqiarui.blog.csdn.net/article/details/51173875 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月10日 23时45分24秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
COMP7404 Machine Learing——KNN
2019-04-30
COMP7404 Machine Learing——SVM
2019-04-30
COMP7404 Machine Learing——ROC
2019-04-30
Python量子计算qiskit
2019-04-30
Python的多线程不是真的多线程(GIL全局解释器锁)
2019-04-30
Python手动读取MNIST数据集
2019-04-30
Python手动读取CIFAR-10数据集
2019-04-30
Pytorch(十一) —— 分布式(多GPU)训练
2019-04-30
Deeplab v3
2019-04-30
NLP 之 Perplexity困惑度
2019-04-30
tensor/矩阵/图片等更换通道,调整size
2019-04-30
本地和colab 中 改变tensorflow的版本
2019-04-30
Camera-ready ddl
2019-04-30
CUB-200鸟类数据集
2019-04-30