Moyshe
Moyshe

Reputation: 1122

Android application info based on it's process name

I'm trying to find some info about apps I find using shell's top command. All I have is a process name (containing package name). Icon and app name would be perfect. I can't find any suitable soultion via google. Any help would be aprreciated;)

To be preemptive, I use top because it's the only way I found to show current processor usage. If someone's familiar with some more API friendly soultion, I'd be grateful.

Example process names I get are:

Upvotes: 1

Views: 2495

Answers (2)

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

Here how you get details. Since you have the package name, you can use it to get the corresponding application name, version, and icon.

List<PackageInfo> packagess = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packagess.size();i++) {
    PackageInfo pack = packagess.get(i);
    if ((!getSysPackages) && (pack.versionName == null)) {
        continue ;
    }

  //this is the application name
    pack.applicationInfo.loadLabel(getPackageManager()).toString();

  //this is the package name
    pack.packageName;

  //this is the version name
    pack.versionName;

  //this is the version code
    pack.versionCode;

  //this is the application icon
    pack.applicationInfo.loadIcon(getPackageManager());
}

Upvotes: 4

Dinesh Prajapati
Dinesh Prajapati

Reputation: 9510

You can try out below code :

private String getTopActivity() {

        ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
        ActivityManager.RunningTaskInfo ar = RunningTask.get(30);
        return ar.topActivity.getClassName().toString();
    }

you have to give the permission of get task in the AndroidManifest.xml

Upvotes: 0

Related Questions