Broadcast receivers

maamirfarooq 745 views 11 slides Oct 28, 2017
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

Broadcast receivers


Slide Content

For instance, a Broadcast receiver triggers battery Low notification that you see on your mobile screen. Other instances caused by a Broadcast Receiver are new friend notifications, new friend feeds, new message etc. on your Facebook app. In fact, you see broadcast receivers at work all the time. Notifications like incoming messages, WiFi Activated/Deactivated message etc. are all real-time announcements of what is happening in the Android system and the applications.

Analogy You have an important social gathering to attend. Because of your shoddy memory, you have requested your friend to notify you a day before the event. Now, because you have ‘registered’ for the said friend’s help, you will get a reminder from him as discussed

A broadcast receiver (short receiver ) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens. For example, applications can register for the ACTION_BOOT_COMPLETED system event which is fired once the Android system has completed the boot process.

What is Broadcast Reciever Base class for components that receive and react to events

Process

Implementing the Broadcast Receiver    Create a subclass of Android’s BroadcastReceiver Implement the onReceive () method : Following are the two arguments of the onReceive () method: Context:  This is used to access additional information, or to start services or activities. Intent:  The Intent object is used to register the receiver.

Enabled can enable or disable Receiver If it is true, other application can Send broadcasts It is the action string, which receiver will be listening

<receiver android:name =" IncomingCall "> <intent-filter> <action android:name =" android.intent.action.PHONE_STATE " /> </intent-filter> </receiver>

public class IncomingCall extends BroadcastReceiver { public void onReceive (Context context , Intent intent) { // Phone call state change then this method will automaticaly called } }