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

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

    How to manually call broadcast receiver to execute the code inside of onReceive method without replicating the code twice.

    Fire BroadcastReceiver using sendBroadcast same action which added in AndroidManifest.xml :

    Intent intent=new Intent(CUSTOM_ACTION_STRING);
    // Add data in Intent using intent.putExtra if any required to pass 
    sendBroadcast(intent);
    

    what is that android:exported parameter means

    As in android:exported doc : Whether or not the broadcast receiver can receive messages from sources outside its application — "true" if it can, and "false" if not

    Means if:

    android:exported=true: other application also able to fire this broadcast receiver using action

    android:exported=false: other application not able to fire this broadcast receiver using action

提交回复
热议问题