Android Project-Mobile security Guardian traffic statistics

Source: Internet
Author: User

# 1. Drawer control
Slidingdrawer: Be sure to configure Android:handle (handles) and android:content (content), and add the layout of the handles and content in the child 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= "I am the contents of the drawer"/>
</LinearLayout>
</SlidingDrawer>
```
# 2. Get Total traffic
"' Java
Trafficstats.getmobilerxbytes (); Total mobile network Download traffic
Trafficstats.getmobiletxbytes ();//Total mobile network upload traffic
Trafficstats.gettotalrxbytes ();//Total Download traffic
Trafficstats.gettotaltxbytes ();//Total network traffic
```
# 3. Get the traffic for a single app
"' Java
Packagemanager pm = Context.getpackagemanager ();
list<packageinfo> Packinfos = pm.getinstalledpackages (0);

PackageInfo.applicationInfo.uid

trafficstats.getuidrxbytes (int uid);//download traffic for an app
trafficstats.getuidtxbytes (int uid);//upload traffic for an app
```
# 4. Traffic Information Save location
Uploaded:/proc/uid_stat/[uid]/tcp_snd |udp_snd
Download:/PROC/UID_STAT/[UID]/TCP_RCV |UDP_RCV

# 5. Get a numeric summary of the file
"' Java
/**
* A digital digest generated by the MD5 algorithm of the file based on the file path
* @param path
* @return
*/
private string GetFileMd5 (string path) {
try {
File File = new file (path);
Get a numeric digest
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 "";
}
}

1  Packagecom.hb.mobilesafe.activities;2 3 ImportCom.hb.demo_mobilesafe. R;4 5 Importandroid.app.Activity;6 Importandroid.net.TrafficStats;7 ImportAndroid.os.Bundle;8 ImportAndroid.text.format.Formatter;9 ImportAndroid.view.Window;Ten ImportAndroid.widget.TextView; One  A  Public classFlowstatisticacitivtyextendsActivity { -     PrivateTextView Tv_wifimobile; -     PrivateTextView tv_mobilestastic; the @Override -     protected voidonCreate (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); A         LongTotalrxbytes = Trafficstats.gettotalrxbytes ();//downstream at         LongTotaltxbytes = Trafficstats.gettotaltxbytes ();//Upstream -          -         LongMobilerxbytes =trafficstats.getmobilerxbytes (); -         LongMobiletxbytes =trafficstats.getmobiletxbytes (); -          -Tv_wifimobile.settext (Formatter.formatfilesize ( This, Totalrxbytes +totaltxbytes)); inTv_mobilestastic.settext (Formatter.formatfilesize ( This, Mobilerxbytes +mobiletxbytes)); -          to          +          -     } the  *}

Android Project-Mobile security Guardian traffic statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.