BroadcastReceiver for Android Chooser not receiving anything

from the CommonsWare Community archives

At June 15, 2020, 5:40pm, sudokai asked:

I’m following the instructions from the official docs and I don’t understand why I don’t receive anything:

Intent sendIntent = new Intent();
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0,
        new Intent(getContext(), FileExportBroadcastReceiver.class),
    startActivity(Intent.createChooser(sendIntent, null, pi.getIntentSender()));

Since implicits intents declared in the manifest no longer work after Android 8, I register the BroadcastReceiver in code:

class FileExportBroadcastReceiver : BroadcastReceiver() {
  override fun onReceive(context: Context?, intent: Intent?) {
    Log.d("FileExportBroadcastReceiver", "broadcast received")
context.registerReceiver(new FileExportBroadcastReceiver(),
                new IntentFilter(Intent.ACTION_SEND));

But I never receive anything when I choose a share target??

At June 15, 2020, 6:02pm, mmurphy replied:

The broadcast is not ACTION_SEND. Instead, just register your receiver in the manifest. Your PendingIntent is set up for a manifest-registered receiver.