13

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);
cjk
  • 45,739
  • 9
  • 81
  • 112
Hareesh
  • 933
  • 3
  • 11
  • 22

1 Answers1

1

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;}
});
Galmani
  • 71
  • 7
Jayesh Khasatiya
  • 2,140
  • 1
  • 14
  • 15
  • (codeSize+dataSize+cacheSize) will it return totalAppSize or only (codeSize+dataSize) will return total App Size – user3233280 Nov 24 '14 at 18:45
  • 1
    i m successfully finding apps list and its memory size for each app but how can i find cpu usage for each app ? – user3233280 Nov 24 '14 at 18:47
  • @user3233280 : Can you please explain as to how you were able to get the ram and CPU usage for the package as I also have the same requirement in an application. Thanks in advance, – Bawender Yandra Nov 20 '18 at 10:41