## 1.抽屉控件
SlidingDrawer:一定要配置android:handle(把手)和android:content(内容),并在子View中添加把手和内容的布局
```java
<SlidingDrawer
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="horizontal" >

<ImageView
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/detail" />

<LinearLayout
android:id="@id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#22000000"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是抽屉里面的内容" />
</LinearLayout>
</SlidingDrawer>
```
## 2.获取总流量
```java
TrafficStats.getMobileRxBytes(); //总的移动网络下载流量
TrafficStats.getMobileTxBytes();//总的移动网络上传流量
TrafficStats.getTotalRxBytes();//总的下载流量
TrafficStats.getTotalTxBytes();//总的网络流量
```
## 3.获取单个应用的流量
```java
PackageManager pm = context.getPackageManager();
List<PackageInfo> packInfos = pm.getInstalledPackages(0);

packageInfo.applicationInfo.uid

TrafficStats.getUidRxBytes(int uid);//某个应用的下载流量
TrafficStats.getUidTxBytes(int uid);//某个应用的上传流量
```
## 4.流量信息保存位置
上传:/proc/uid_stat/[uid]/tcp_snd |udp_snd
下载:/proc/uid_stat/[uid]/tcp_rcv |udp_rcv

## 5.获取文件的数字摘要
```java
/**
* 根据文件路径得到文件的md5算法生成的数字摘要
* @param path
* @return
*/
private String getFileMd5(String path){
try {
File file = new File(path);
//得到一个数字摘要器
MessageDigest digest = MessageDigest.getInstance("MD5");
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer))!=-1){
digest.update(buffer,0,len);
}
byte[] result = digest.digest();
StringBuilder sb = new StringBuilder();
for(byte b:result){
int number = b&0xff;
String str = Integer.toHexString(number);
if(str.length()==1){
sb.append("0");
}
sb.append(str);
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}

 package com.hb.mobilesafe.activities;

 import com.hb.demo_mobilesafe.R;

 import android.app.Activity;
import android.net.TrafficStats;
import android.os.Bundle;
import android.text.format.Formatter;
import android.view.Window;
import android.widget.TextView; public class FlowStatisticAcitivty extends Activity {
private TextView tv_wifimobile;
private TextView tv_mobilestastic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_flowstastic);
tv_mobilestastic=(TextView) findViewById(R.id.tv_mobilestastic);
tv_wifimobile=(TextView) findViewById(R.id.tv_wifimobile);
long totalRxBytes = TrafficStats.getTotalRxBytes();//下行
long totalTxBytes = TrafficStats.getTotalTxBytes();//上行 long mobileRxBytes = TrafficStats.getMobileRxBytes();
long mobileTxBytes = TrafficStats.getMobileTxBytes(); tv_wifimobile.setText(Formatter.formatFileSize(this, totalRxBytes + totalTxBytes));
tv_mobilestastic.setText(Formatter.formatFileSize(this, mobileRxBytes + mobileTxBytes)); } }

最新文章

  1. 关于mysql数据库的备份和还原
  2. inno setup读取注册表遇到的一个坑
  3. js倒计时跳转页面
  4. Git的常用操作,记录下
  5. get( )与getline( )区别
  6. 【linux】grub加密
  7. php的webservice的soapheader认证问题
  8. android 布局居中
  9. 制作下拉菜单(PopupList)
  10. Unity3d之Socket UDP协议
  11. 调用test case集,并生成测试报告
  12. 高性能web系统的架构和系统优化
  13. JS中setAttribute的兼容性问题(摘自leejersey)
  14. 用Owin Host实现脱离IIS跑Web API单元测试
  15. 协议端口号(protocol port number)
  16. Java常用异常整理
  17. bzoj 2565: 最长双回文串
  18. wepy 初探
  19. [Educational Round 5][Codeforces 616F. Expensive Strings]
  20. 通过P3P头实现跨域设置cookie

热门文章

  1. jQuery通过event获取点击事件的事件对象
  2. Hihocoder 1325 (splay)
  3. NOIP2010 提高组合集
  4. Screenshot: available via screen
  5. [转] python 获取本机ip地址的两种实现方法
  6. vijos 1237 隐形的翅膀
  7. Android: 长按及松开处理
  8. C++对象内存分布(3) - 菱形继承(virtual)
  9. Codeforces 196 D. The Next Good String
  10. R语言学习笔记-Error in ts(x):对象不是矩阵问题解决