Android - How to trigger a Broadcast Receiver to call its onReceive() method?

前端 未结 4 699
天命终不由人
天命终不由人 2021-02-18 21:46

I have scheduled alarm for my application.

I have implemented broadcast receiver to be triggered once the alarm time reaches.

How to manually call broadcast re

4条回答
  •  礼貌的吻别
    2021-02-18 22:24

    You need to mention the action which is required to be filter by Android OS to notify you. i.e.: inside manifest file,

    
    
        //this should be unique string as action
    
    

    and

    whenever you want to call broadcast receiver's onReceive method,

    Intent intent = new Intent();
    intent.setAction("com.example.alarm.notifier");
    sendBroadcast(intent);
    

提交回复
热议问题