进程

xiaoxiao2021-03-01  29

简介

xxx

进程名

private String processName() { String currentProcName = ""; int pid = android.os.Process.myPid(); ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { if (processInfo.pid == pid) { currentProcName = processInfo.processName; break; } } return currentProcName; }

推荐

package util; import android.text.TextUtils; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; /** * Created on 2018/8/28. * * @desc AppUtils */ public class AppUtils { /** * 进程号对应进程名 * * @param pid 进程号 * @return 进程名 */ public static String getProcessName(int pid) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline")); String processName = reader.readLine(); if (!TextUtils.isEmpty(processName)) { processName = processName.trim(); } return processName; } catch (Throwable throwable) { throwable.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException exception) { exception.printStackTrace(); } } return null; } }
转载请注明原文地址: https://www.6miu.com/read-4200359.html

最新回复(0)