1

I'm trying to send a broadcast intent with extras using ADB to a BroadcastReceiver that is registered at runtime using Context.registerReceiver(BroadcastReceiver, IntentFilter).

This is what I'm sending from shell to a USB connected device with ADB daemon enabled and reachable:

adb shell am broadcast -a app.example.ACTION -ei EXTRA_INT 1 -es EXTRA_STRING "1234"

Anyway that intent is not received by my broadcast receiver that instead receives the intent if I remove all the extras and run:

adb shell am broadcast -a app.example.ACTION

Then my BroadcastReceiver is notified with the sent intent, but I need to add extras to that intent.

I've read from some sources that when you provide extras to am broadcast the -n option is mandatory (see Xi Wei's comment here) making the intent explicit, but I don't know how I can refer to a run time registered BroadcastReceiver that is an anonymous class using the explicit intent format provided on ADB documentation com.example.app/.ExampleActivity, I think that it is not possible.

This is the code that creates the BroadcastReceiver:

public class MyClass {

  public void register() {
     initReceiver();
     getContext().registerReceiver(mBarcodeReadBroadCast, new IntentFilter("app.example.ACTION"));
  }

  private void initReceiver() {
    mBarcodeReadBroadCast = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
              
        }
    };
  }
}

Maybe there are some other options to send an intent to a runtime registered BroadcastReceiver with extras, does anyone know how to do that?

Lino
  • 5,084
  • 3
  • 21
  • 39
Francesco
  • 363
  • 2
  • 11

0 Answers0