3

I'm working on a combination of few big projects which I'm not much familiar. I have a Local broadcast events and it register from the script.

context.registerReceiver(stReceiver, stIntents);

private BroadcastReceiver stReceiver = new BroadcastReceiver() {

        @SuppressWarnings("unchecked")
        @Override
        public void onReceive(Context context, Intent intent) {

}
};

I need to find out where is this broadcastReceiver calling from? Is there any way to find out from which class .sendBroadcast(intent); calls?

Zusee Weekin
  • 1,348
  • 2
  • 18
  • 41

4 Answers4

1

I'm not 100% sure, whether this works or not but give it a try. Use Log statement to print intent.getClass().getName() in onReceive function. Since the intent is passed from calling class it will provide the class name.

0

AFAIK context.registerReceiver(stReceiver, stIntents); itself is .sendBroadcast(intent); here.

.sendBroadcast(intent); is used in global broadcast. For local registerReceiver(BroadcastReceiver receiver, IntentFilter filter) is sufficient to start the broadcast.

 I need to find out where is this broadcastReceiver calling from?

So in your case context.registerReceiver(stReceiver, stIntents); itself is the starting point.

For more info:

http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html

Ranjit
  • 5,130
  • 3
  • 30
  • 66
  • Thanks But I'm in doubt. Local broadcast also has a method called sendBroadcast(Intent intent) in API. So what is the use of it? – Zusee Weekin Feb 24 '16 at 01:38
0

You Can check the action for the Intent. and search the action in your project

String action =intent.getAction();

BalaramNayak
  • 1,295
  • 13
  • 16
-1
You can put check 

like this

@Override
    public void onReceive(Context context, Intent intent) {

if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
//Do your part

}
}

In place of Intent.ACTION_MEDIA_BUTTON you can use your own action you mention in the intent filter while registering a receiver
Rohit Heera
  • 2,709
  • 2
  • 21
  • 31