如何以编程方式显示所有的应用程序数据的使用有的、应用程序、方式、数据

2023-09-05 04:25:17 作者:愚昧的笑

在的Andr​​oid 4.0开始,我们已经在phone.Please数据使用量控制选项查看连接屏幕截图做进一步的了解。

In Android 4.0 onwards we have data usage control options in the phone.Please check the attached screen shot for further understanding.

http://developer.android.com/about/versions/ Android的4.0 highlights.html

现在我有一些要求,从我的应用程序检查这些东西(在特定时间段的所有应用程序的数据使用量/特定日期),任何一个指导我,我怎么能做到这一点,我也使用下面类网络使用细节

Now i have some requirement to check these things(All Application's Data usage in specific time period/specific days) from my application , any one guide me how can i achieve this i am also using below class for Network Usage details

http://developer.oesf.biz/em/developer/reference/eggplant/android/net/NetworkStatsHistory.html

请检查下面的链接图片,我需要开发同类型的应用程序

Please check below link images i need to develop same kind of application

http://developer.android.com/sdk/图片/ 4.0 /使用-全lg.png

http://developer.android.com/sdk/图片/ 4.0 /使用-地图 - lg.png

感谢您分享您的code,但我需要知道所使用的每个应用程序,而不是所有的应用程序数据 到目前为止,我在观察到的链接没有人在谈论单个应用程序的数据使用情况 我已经知道如何显示在设备中安装的应用程序,现在我想知道什么是使用每个应用程序的数据。

Thanks for sharing your code but i need to know data used by each application instead of all applications so far i observed in the links no one is talking about data usage of individual applications I already know how to show installed applications in the device now i would like to know what's the data used by each and every application

我在设备使用跌破$ C $下安装的应用程序列表

I am using below code for list of installed applications in the device

private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
    ArrayList<PInfo> res = new ArrayList<PInfo>();  

    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);

    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);
        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PInfo newInfo = new PInfo();    
        newInfo.setAppname(p.applicationInfo.loadLabel(getPackageManager()).toString());
        newInfo.setPname(p.packageName);
        newInfo.setVersionName(p.versionName);
        newInfo.setVersionCode(p.versionCode);
        newInfo.setIcon(p.applicationInfo.loadIcon(getPackageManager()));

        res.add(newInfo);
    }
    return res; 
}

现在告诉我怎么知道什么是由每个应用程序的数据。

Now tell me how to know what's the data used by each application

实际上我需要一个解决方案,它给出了应用数据的使用在给定时间周期,即在两天间

Actually i need a solution which gives Data usage of applications in a given time period i.e. in between two days

推荐答案

您可以使用 android.net.TrafficStats 获取网络的使用细节。

You Can use the android.net.TrafficStats for getting the network usage details.

请找到相同的示例程序。

please find sample program for the same.

package com.anchit.trafficstatus;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class TrafficStatus extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Log.e("bytes recvd",""+android.net.TrafficStats.getMobileRxBytes());

        Log.e("Total","Bytes received"+android.net.TrafficStats.getTotalRxBytes());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}