publicstaticStringgetProcessNameDevice(finalContext context){intmyPid=Process.myPid();if(context ==null|| myPid <=0) {return""; } ActivityManager.RunningAppProcessInfomyProcess=null;// 获取ActivityManagerActivityManageractivityManager=(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);...
publicstaticStringgetProcessNameDevice(finalContextcontext){intmyPid=Process.myPid();if(context==null||myPid<=0){return"";}ActivityManager.RunningAppProcessInfomyProcess=null;// 获取ActivityManagerActivityManageractivityManager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);if(activityM...
private static String getProcessName() { BufferedReader cmdlineReader = null; try { cmdlineReader = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/" + android.os.Process.myPid() + "/cmdline"), "iso-8859-1")); int c; StringBuilder processName = new StringBuilder(); ...
方法一:大叔发现,在android api28的时候新增了一个方法:Application.getProcessName() Application.getProcessName()方法直接返回当前进程名。这不就是我们想要的API吗! 但是这个方法只有在android9【也就是aip28】之后的系统才能调用。 public class ProcessUtil { /** * 通过Application新的API获取进程名,无需反射,...
publicclassProcessUtil{/** * 通过Application新的API获取进程名,无需反射,无需IPC,效率最高。 */publicstaticStringgetCurrentProcessNameByApplication(){if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.P){returnApplication.getProcessName();}returnnull;}} ...
private boolean isMainProcess() { //获取当前进程名,并与主进程对比,来判断是否为主进程 String processName = ProcessUtil.getCurrentProcessName(this); Log.e(TG, "isMainProcess processName=" + processName); return BuildConfig.APPLICATION_ID.equals(processName); ...
API28 新增方法 Application # getProcessName() 代码如下 /** * AP28以上才能使用 * 直接获取到进程名称,不会有跨进程,反射的耗时操作 */ fun getCurrentProcessNameOnP():String?{ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){ return Application.getProcessName() ...
如下是Android提供的两种获取方式,get_command_line将获取其中所有的字符串,而get_process_name只会获取argv[0]指向的字符串,对纯native进程而言,它通常是可执行文件的名称,也可以理解为进程名。不过对于Android应用而言,它却有别的含义。此处按下不表,后文再述。
Manager.RunningAppProcessInfo>processes = manager.getRunningAppProcesses();intpid=android.os.Process.myPid();StringprocessName="";for(ActivityManager.RunningAppProcessInfo process : processes) {if(process.pid == pid) {processName=process.processName;break;}}Log.d("ProcessName", processName);...
}//2)通过反射ActivityThread获取当前进程名currentProcessName=getCurrentProcessNameByActivityThread();if(!TextUtils.isEmpty(currentProcessName)){returncurrentProcessName;}//3)通过ActivityManager获取当前进程名currentProcessName=getCurrentProcessNameByActivityManager(context);returncurrentProcessName;}/** * 通过...