欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  技术分享

Android应用流量统计_APP数据及wifi流量统计源代码

程序员文章站 2022-03-01 13:02:23
...

这是一个App消耗流量的统计、有wifi数据统计和移动数据统计、用柱状图和折线图体现了流量消耗的趋势直观明了、运行效果如下、有兴趣的哥们可以下载源代码看看、非常不错的、话不多说、直接上图了

Android应用流量统计_APP数据及wifi流量统计源代码


onCreate代码

protected void onCreate(Bundle savedInstanceState)
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_traffic);
    mCloumLayout = (LinearLayout)findViewById(R.id.traffic_cloum_content);
     AseoZdpAseo.initType(this,AseoZdpAseo.INSERT_TYPE);
    int width = 0;
    mDbManager= new DbManager(this);
    infos = mDbManager.queryTotal(DbManager.NETWORK_TYPE_WIFI);
    int i;
    long total = 0;
    for(i = 0; i < infos.size(); i  )
    {
        total  = infos.get(i).traffic;
    }
    ((TextView)findViewById(R.id.traffic_wifi_text)).setText(switchUnit(total));
    width = (infos.size()   1)*50;
    
    total = 0;
    infos = mDbManager.queryTotal(DbManager.NETWORK_TYPE_MOBILE);
    for(i = 0; i < infos.size(); i  )
    {
        total  = infos.get(i).traffic;
    }
    ((TextView)findViewById(R.id.traffic_gprs_text)).setText(switchUnit(total));
    if(width < (infos.size()   1)*50)
        width = (infos.size()   1)*50;
    
    mGeomark = new Geomark(this);
    mGeomark.setData(infos);
    mRain = new RainAnimotion(this);
    mRain.setData(infos);
    mRain.setVisibility(View.GONE);
    if(width < Utils.getScreenWidth(this))
    {
        mCloumLayout.addView(mGeomark, new LayoutParams(Utils.getScreenWidth(this), LayoutParams.WRAP_CONTENT));
        mCloumLayout.addView(mRain, new LayoutParams(Utils.getScreenWidth(this), LayoutParams.WRAP_CONTENT));
    }
    else
    {
        mCloumLayout.addView(mGeomark, new LayoutParams(width, LayoutParams.WRAP_CONTENT));
        mCloumLayout.addView(mRain, new LayoutParams(width, LayoutParams.WRAP_CONTENT));
    }
    
    findViewById(R.id.traffic_gprs).setOnClickListener(mOnClickListener);
    findViewById(R.id.traffic_titleBar_back).setOnClickListener(mOnClickListener);
    findViewById(R.id.traffic_graph_tip_image).setOnClickListener(mOnClickListener);
    findViewById(R.id.traffic_wifi).setOnClickListener(mOnClickListener);
    mTipTextView = (TextView)findViewById(R.id.traffic_graph_tip_text);
    
}


OnClickListener处理

public void onClick(View view)
{
    int id = view.getId();
    switch (id)
        {
        case R.id.traffic_gprs:
            type = "移动流量";
            infos = mDbManager.queryTotal(DbManager.NETWORK_TYPE_MOBILE);
            mGeomark.setData(infos);
            mRain.setData(infos);
            mTipTextView.setText(type   graph);
            if(isGeomark)
            {
                mGeomark.setVisibility(View.GONE);
                mGeomark.setVisibility(View.VISIBLE);
            }
            else {
                mRain.setVisibility(View.GONE);
                mRain.setVisibility(View.VISIBLE);
            }
            break;
        case R.id.traffic_titleBar_back:
            finish();
            break;
        case R.id.traffic_graph_tip_image:
            {
                if(isGeomark)
                {
                    isGeomark = false;
                    graph = "柱状图";
                    mTipTextView.setText(type   graph);
                    mGeomark.setVisibility(View.GONE);
                    mRain.setVisibility(View.VISIBLE);
                }
                else {
                    isGeomark = true;
                    graph = "折线图";
                    mTipTextView.setText(type   graph);
                    mGeomark.setVisibility(View.VISIBLE);
                    mRain.setVisibility(View.GONE);
                }
                break;
            }
        case R.id.traffic_wifi:
            type = "wifi数据";
            infos = mDbManager.queryTotal(DbManager.NETWORK_TYPE_WIFI);
            mGeomark.setData(infos);
            mRain.setData(infos);
            mTipTextView.setText(type   graph);
            if(isGeomark)
            {
                mGeomark.setVisibility(View.GONE);
                mGeomark.setVisibility(View.VISIBLE);
            }
            else {
                mRain.setVisibility(View.GONE);
                mRain.setVisibility(View.VISIBLE);
            }
            break;
        default:
            break;
        }
}


权限申请

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />


源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1dDBINux 密码: s9pr