Java tutorial
//package com.java2s; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.content.Context; import java.util.List; public class Main { public static String getCurProcessName(Context context) { int pid = android.os.Process.myPid(); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (activityManager == null) { return null; } List<RunningAppProcessInfo> runningProcessList = activityManager.getRunningAppProcesses(); if (runningProcessList == null || runningProcessList.isEmpty()) { return null; } for (ActivityManager.RunningAppProcessInfo appProcess : runningProcessList) { if (appProcess.pid == pid) { return appProcess.processName; } } return null; } public static boolean isEmpty(String str) { if (str == null) { return true; } for (int i = 0, length = str.length(); i < length; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; } }