Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android get process name inside BroadcastReceiver

I'm stuck in this trouble and I can't figure it out. I googled a lot, but nothing gave me an answer.

I explain:
I have a BroadCastReceiver which runs in a different process (android:process=":anotherProcess")

I want to get this process name inside my BroadcastReceiver.

In this case for example, it could be: com.my.package:anotherProcess

Is it possible? How can I do it?

like image 942
edoardotognoni Avatar asked Nov 03 '22 14:11

edoardotognoni


1 Answers

I've found a way. For anyone who will need this:

     int id = Process.myPid();
     String myProcessName =context.getPackageName();

     ActivityManager actvityManager = (ActivityManager)context.getSystemService( context.ACTIVITY_SERVICE );
     List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

     for(RunningAppProcessInfo procInfo : procInfos) {
         if (id == procInfo.pid)
         {
             myProcessName = procInfo.processName;
         }
     }
like image 141
edoardotognoni Avatar answered Nov 11 '22 11:11

edoardotognoni