Why is my BroadcastReceiver not receiving broadcasts from another application?

Appendix A has this BroadcastReceiver in its manifest (inside <application>):

     

And this receiver:

public class RemoteControl extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
      Log.w(TAG, "Look what I did!");
  }
}

I am trying to call this from application B:

public void onClick(View v) {
  Log.w(TAG, "Sending stuff");
  Intent i = new Intent("app.a.remotecontrol");
  i.setData("http://test/url");
  sendBroadcast(i);
}

For some reason, onReceive () in application A never starts, even if it is broadcast from application B. What could be the reason for this?

EDIT AND SOLUTION . I forgot to write that before the broadcast I used setData () in Intent. This is really a problem: as soon as I deleted setData (), the translation worked as intended.

+3
source share
1 answer

, setData() Intent . : setData(), .

putExtra() Intent:

Intent i = new Intent("app.a.remotecontrol");
i.putExtra("url", "http://test/url");
sendBroadcast(i);
+3

Source: https://habr.com/ru/post/1753151/


All Articles