Docsity

Android Broadcast Receiver: Understanding and Implementing, Lecture notes of Computer Science

Partial preview of the text

Download Android Broadcast Receiver: Understanding and Implementing and more Lecture notes Computer Science in PDF only on Docsity!

Mobile Application Development

(Android)

(CS-414)

Momina Tayyaba

Lecturer

The University of Faisalabad

Announcements

What’s going on around you?

  • Things happen in OS
  • That event could be of interest to many applications
  • This even is broadcasted as a “Broadcast”
  • If you are interested in such an event, you should have a BroadcastReceiver in your app
  • Waits for a broadcast to be received
  • Once received, it runs a piece of java code.

How to Create a Broadcast Receiver

  • Declare a receiver in Manifest file
  • Create a java class that receives broadcast

Manifest Entry

<intent-filter> </intent-filter>

How to Create a Broadcast Receiver

  • Declare a receiver in Manifest file
  • Create a java class that receives broadcast

Java Receiver public class MyReceiver extends BroadcastReceiver {

@Override public void onReceive(Context context, Intent intent) {

// this code runs once ☺ Toast.makeText(context, "Broadcast Received", Toast.LENGTH_LONG).show();

} }

Example Broadcasts

android.intent.action.ACTION_POWER_CONNECTED android.intent.action.ACTION_POWER_DISCONNECTED android.intent.action.ACTION_SHUTDOWN android.intent.action.AIRPLANE_MODE android.intent.action.BATTERY_CHANGED android.intent.action.BATTERY_LOW android.intent.action.BATTERY_OKAY android.intent.action.BOOT_COMPLETED android.intent.action.CAMERA_BUTTON

Example Broadcasts

android.intent.action.DATA_SMS_RECEIVED

android.intent.action.DATE_CHANGED

android.intent.action.DEVICE_STORAGE_LOW

android.intent.action.DEVICE_STORAGE_OK

android.intent.action.DOCK_EVENT

android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE

android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE

android.intent.action.FETCH_VOICEMAIL

Example Broadcasts

android.provider.Telephony.SIM_FULL

android.provider.Telephony.SMS_CB_RECEIVED

android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED

android.provider.Telephony.SMS_RECEIVED

android.provider.Telephony.SMS_REJECTED

android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RE

CEIVED

android.provider.Telephony.WAP_PUSH_RECEIVED

Questions?