流量统计原理,sliding抽屉的使用

本文介绍了流量统计的基本原理,包括用户ID在流量记录中的作用,以及在Android系统中如何通过API获取应用程序的下载和上传流量。此外,还详细讲解了SlidingDrawer组件的使用,包括其必须配置的属性如handle、content,以及如何设置抽屉的方向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

54.流量统计原理

uid:user id 用户id。操作系统分配给应用程序的一个固定的编号。一旦应用程序装到手机上,id就固定不变了。

用户id是自增长的,卸载软件时uid会被回收,再新装软件时,系统会把回收的uid分配给新装的软件。

stat:状态

tcp_rcv:receive 接收 下载

tcp_snd:send 发送 上传


应用程序下载的流量在/proc/uid_stat/uid/tcp_rcv文件中记录
应用程序上传流量在/proc/uid_stat/uid/tcp_snd文件中记录

android2.3之前获得流量需要读取上面的文件,2.3之后Google工程师给我们提供了读取流量的API。


List<ApplicationInfo> infos = pm.getInstalledApplications(0);

for(ApplicationInfo info : infos){

int uid = info.uid;

应用程序下载和上传的流量

long uidRxBytes = TrafficStats.getUidRxBytes(uid);

long uidTxBytes = TrafficStats.getUidTxBytes(uid);

获取手机3g/2g网络上传和下载的总流量

TrafficStats.getMobileTxBytes();
TrafficStats.getMobileRxBytes();
手机全部网络接口 包括wifi,3g、2g上传的总流量
TrafficStats.getTotalTxBytes();
TrafficStats.getTotalRxBytes();

}


55.sliding抽屉的使用

SlidingDrawer与其他控件不同,它有一些必须配置的属性:id、handle、content。handle是把手,content是抽屉里包含的内容。定义时,handle和content属性也是以@+id/name的形式定义的。该控件必须包含子孩子:把手和抽屉把手可以是布局文件,但抽屉必须是布局文件),他们都是通过@id来表明自己是把手还是抽屉。抽屉里的内容写在布局文件中。抽屉的方向默认是竖直的,从下往上拉的,若要改为从右向左拉,改方向为水平方向即可。如下:

<SlidingDrawer
    android:id="@+id/sd_show"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:content="@+id/my_content"
    android:handle="@+id/my_handle"
    android:orientation="horizontal" >

    <ImageView
        android:id="@id/my_handle"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:id="@id/my_content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#22000000" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="我是抽屉里的内容" />
    </LinearLayout>
</SlidingDrawer>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值