get Process Name From Activity Manager - Android Android OS

Android examples for Android OS:Process

Description

get Process Name From Activity Manager

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;

public class Main {
    public static String getProcessNameFromActivityManager(Context ctx) {
        String processName = "";
        int pid = android.os.Process.myPid();

        ActivityManager manager = (ActivityManager) ctx
                .getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo processInfo : manager
                .getRunningAppProcesses()) {
            if (processInfo.pid == pid) {
                processName = processInfo.processName;
                break;
            }//from ww w .  jav  a2s .  c o m
        }

        return processName;
    }
}

Related Tutorials