7

I am looking for a way to determine what application sent an Intent. At present, I've registered a BroadcastReceiver and have been trying to work with Binder.getCallingPid, but it usually returns my app's PID. What I find weird is the usually part, my app does occasionally get the PID of the app that sent the Intent, but it's not often and I cannot seem to pin down the conditions for which this is true.

Is there a way to accurately determine what app initiated a call to BroadcastReceiver.onReceive?

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("Receiver", "Sender's PID: " + Binder.getCallingPid());
}
Onik
  • 19,396
  • 14
  • 68
  • 91
Tom
  • 6,947
  • 7
  • 46
  • 76
  • Are you using the local broadcast receiver? – wi1 Jul 10 '14 at 16:31
  • No, the idea is to register the receiver with the system (Context.registerReceiver) and determine which app sends Intents I'm listening for. – Tom Jul 10 '14 at 16:37
  • Thats good because it would never leave your app, Whats your manifest entry look like? – wi1 Jul 10 '14 at 16:49
  • It's not registered in my Manifest.xml, it's registered dynamically with an IntentFilter and Context.registerReceiver. I'm looking for a general solution though, so it shouldn't depend on what actions I'm registering for. – Tom Jul 10 '14 at 16:51

0 Answers0