Guest User

Untitled

a guest
Nov 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // High performance
  2. public static String getProcessName() {
  3. try {
  4. File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
  5. BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
  6. String processName = mBufferedReader.readLine().trim();
  7. mBufferedReader.close();
  8. return processName;
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. return null;
  12. }
  13. }
  14.  
  15. // Normal
  16. public static String getProcessName(Context cxt, int pid) {
  17. ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
  18. List<RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
  19. if (runningApps == null) {
  20. return null;
  21. }
  22. for (RunningAppProcessInfo procInfo : runningApps) {
  23. if (procInfo.pid == pid) {
  24. return procInfo.processName;
  25. }
  26. }
  27. return null;
  28. }
Add Comment
Please, Sign In to add comment