获取当前进程号和当前进程名
int pid = Process.myPid();//import android.os.Process不然会报错!
String processName = "";
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : list){
if (runningAppProcessInfo.pid == pid){
processName = runningAppProcessInfo.processName;
}
}
Log.i(TAG,"当前进程号:" + pid);
Log.i(TAG,"当前进程名称:" + processName);