Java tutorial
//package com.java2s; //License from project: Apache License import android.app.ActivityManager; import android.content.Context; import android.text.TextUtils; import java.util.List; public class Main { /** * whether this process is named with processName */ public static boolean isNamedProcess(Context context, String processName) { if (context == null || TextUtils.isEmpty(processName)) { return false; } int pid = android.os.Process.myPid(); ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses(); if (processInfoList != null) { for (ActivityManager.RunningAppProcessInfo processInfo : processInfoList) { if (processInfo.pid == pid && processName.equalsIgnoreCase(processInfo.processName)) { return true; } } } return false; } }