How to send a custom broadcast action to receivers in manifest?

前端 未结 6 533
心在旅途
心在旅途 2020-12-15 07:48

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {
            


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-15 08:30

    I use Android 8.

    Then you have to use an explicit Intent, one that identifies the receiver, such as:

    sendBroadcast(new Intent(this, MyReceiver.class).setAction("MyAction"));
    

    See Broacast limitations in Android 8 release docs.

提交回复
热议问题