Skip to content

Instantly share code, notes, and snippets.

@BCsl
Created May 23, 2016 06:33
Show Gist options
  • Select an option

  • Save BCsl/aa3711cc51a99bd6be1a0704a3aceaa5 to your computer and use it in GitHub Desktop.

Select an option

Save BCsl/aa3711cc51a99bd6be1a0704a3aceaa5 to your computer and use it in GitHub Desktop.
MultiProcess
/**
* 获取当前进程名
* @param context
* @return
*/
public static String getCurrProcessName(Context context) {
try {
final int currProcessId = android.os.Process.myPid();
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
if (processInfos != null) {
for (ActivityManager.RunningAppProcessInfo info : processInfos) {
if (info.pid == currProcessId) {
return info.processName;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment