get Process Name - Android Android OS

Android examples for Android OS:Process

Description

get Process Name

Demo Code


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

import java.util.List;

public class Main {

    public static String getProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> infos = manager
                .getRunningAppProcesses();
        if (infos != null) {
            for (ActivityManager.RunningAppProcessInfo processInfo : infos) {
                if (processInfo.pid == pid) {
                    return processInfo.processName;
                }/*w  w  w. j  ava2 s.  c om*/
            }
        }
        return null;
    }
}

Related Tutorials