get Current Process Name - Android Android OS

Android examples for Android OS:Process

Description

get Current Process Name

Demo Code

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

public class Main {

  private static Application sApp;

  public static String getCurrentProcessName() {
    int pid = android.os.Process.myPid();
    ActivityManager activityManager = (ActivityManager) sApp.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
      if (appProcess.pid == pid) {
        return appProcess.processName;
      }//from   ww  w. j  a v  a 2 s.c  o  m
    }
    return null;
  }

}

Related Tutorials