Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // High performance
- public static String getProcessName() {
- try {
- File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
- BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
- String processName = mBufferedReader.readLine().trim();
- mBufferedReader.close();
- return processName;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- // Normal
- public static String getProcessName(Context cxt, int pid) {
- ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
- List<RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
- if (runningApps == null) {
- return null;
- }
- for (RunningAppProcessInfo procInfo : runningApps) {
- if (procInfo.pid == pid) {
- return procInfo.processName;
- }
- }
- return null;
- }
Add Comment
Please, Sign In to add comment