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

前端 未结 6 538
心在旅途
心在旅途 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:50

    Change the MainActivity's code as follows:

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

提交回复
热议问题