Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve All and Running application sizes, CPU usage programmatically?

I am implementing android application for getting All applications and Running applications and their sizes, usage and CPU usage.

But i'm only get the all and running applications Icon, Label and Packegename not able to retrieve sizes, usage and CPU usage.

I saw an application in GooglePlayStore that is AndroidSystem Info. In that app all system information given.

I want to retrieve that information programmatically.

Can anyone please help me to get total system information

thanks in advance.................

Here is my code:

For getting All Applications:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pm = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
ApplicationInfo entry = (ApplicationInfo) mListAppInfo.get(position);
ImageView ivAppIcon = (ImageView) v.findViewById(R.id.ivIcon);
TextView tvAppName = (TextView) v.findViewById(R.id.tvName);
TextView tvPkgName = (TextView) v.findViewById(R.id.tvPack);

// set data to display
ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
tvAppName.setText(entry.loadLabel(mPackManager));
tvPkgName.setText(entry.packageName);

For Getting Running Applications

ActivityManager activityManager = (ActivityManager)  getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runAppList = am.getRunningAppProcesses();
int listsize = runAppList.size();
Log.v("tag", "listsize..." + listsize);
like image 735
Hareesh Avatar asked Feb 01 '13 09:02

Hareesh


1 Answers

You can Do this using IPackageStatsObserver.aidl interface. Create package android.content.pm in your app src directory and Implement below code It will return all appliscation size.

Method getPackageSizedInfo =pm.getClass().getMethod("getPackageSizeInfo",String.class,IPackageStatsObserver.class);

getPackageSizedInfo.invoke(pm, pkgname,new IPackageStatsObserver.Stub() {
@Override 
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)throws RemoteException {double size=(double)pStats.codeSize+pStats.cacheSize+pStats.dataSize;}
});
like image 125
Jayesh Khasatiya Avatar answered Nov 15 '22 19:11

Jayesh Khasatiya