Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.ActivityManager; import android.content.Context; import java.util.ArrayList; import java.util.List; public class Main { public static String getProcessName(Context context) { int pid = android.os.Process.myPid(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) { if (appProcess.pid == pid) { return appProcess.processName; } } return null; } public static List<String> getProcessName(Context context, String packageName) { List<String> list = new ArrayList<String>(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) { if (appProcess.processName.startsWith(packageName)) { list.add(appProcess.processName); } } return list; } }