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

前端 未结 4 730
天命终不由人
天命终不由人 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:14

    Here is a more type-safe solution:

    • AndroidManifest.xml:

      
      
    • CustomBroadcastReceiver.java

      public class CustomBroadcastReceiver extends BroadcastReceiver
      {
          @Override
          public void onReceive(Context context, Intent intent)
          {
              // do work
          }
      }
      
    • *.java

      Intent i = new Intent(context, CustomBroadcastReceiver.class);
      context.sendBroadcast(i);
      

提交回复
热议问题