SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Android Application DevelopmentBroadcast ReceiverAhsanul Karimahsanul.karim@sentinelbd.comSentinel Solutions Ltd.http://www.sentinelbd.com
Application Building Blocks
Android Application AnatomyActivitiesProvides User InterfaceUsually represents a Single ScreenCan contain one/more ViewsExtendsthe Activity Base classServicesNoUser InterfaceRuns in BackgroundExtends the Service Base ClassIntent/Broadcast ReceiverReceives and Reacts to broadcast IntentsNo UI but can start an ActivityExtends the BroadcastReceiver Base ClassContent ProviderMakes application data available to other appsData stored in SQLite databaseExtends the ContentProviderBase classApplication= Set of Android Components
Broadcast ReceiversA broadcast receiver is a component that responds to system-wide Broadcast announcements. Many broadcasts originate from the system—for example, a Broadcast announcing that the screen has turned off, the battery is low, or a picture was captured or an SMS is received. Applications can also initiate broadcasts—for example, to let other Applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service/or start an activity to perform some work based on the event.
Android Application AnatomyActivity 1 Activity 2 BroadcastReceiverServiceUIOSIntentsDirected IntentsBroadcast IntentsBIG PICTURE
Broadcast ReceiversActivityWe’ll use a Broadcast Receiver to capture SMS receive eventWe capture the SMS receive event and launch an Activity to show the sms and give user an option to reply the SMSBroadcastReceiverOS
Broadcast ReceiversCreate a new project BroadcastReceiverDemoA broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. In this case the intent is detected by android.provider.Telephony.SMS_RECEIVEDTo do this we’ll create a class SMSReceiver that extends BroadcastReceiver class and define the method onReceive()BroadcastReceiver
Broadcast Receivers (Contd.)3. We also need to add SMSReceiver as receiver of a particular Intent (SMS received) which is identified by android.provider.Telephony.SMS_RECEIVEDBroadcastReceiver
Broadcast Receivers (Contd.)4. Also we have to add permission for receiving SMSBroadcastReceiver
Broadcast Receivers (Contd.)5. Now we run the application6. Now we use emulator control to send sms
Receiving SMSBundle bundle = intent.getExtras();        SmsMessage[] msgs = null;String str = "";String address="";if (bundle != null){//---retrieve the SMS message received---Object[] pdus = (Object[]) bundle.get("pdus");msgs = new SmsMessage[pdus.length];for (int i=0; i<msgs.length; i++)                {msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                str += "SMS from " + msgs[i].getOriginatingAddress();                     str += " :";str += msgs[i].getMessageBody().toString();str += "\n";                    address=msgs[i].getOriginatingAddress();Toast.makeText(context, str, Toast.LENGTH_LONG).show();                }
Sending SMS1. Add permission in menifest.xml2. We add the following code for sending SMS from anywhere of our application
ExerciseWe’ll create a replica of SMS application of AndroidApplication will have a basic TabActivity with 3 tabs (Activities)Send- will give user option to send sms (2 input fields for number and text)All sent SMS will be saved in databaseInbox- (List Activity) which will fetch all received SMS from databaseSent- (ListActivity) which will fetch all sent SMSA broadcast receiver which will receive SMS and save them to database

More Related Content

PPTX
Circuit Switching
PPTX
Http and its Applications
PPTX
HTTP request and response
PPT
Np unit2
PPTX
SNMP/SMTP/MIME
PPT
Distributed System
PPT
Webservices
Circuit Switching
Http and its Applications
HTTP request and response
Np unit2
SNMP/SMTP/MIME
Distributed System
Webservices

What's hot (20)

PPTX
Socket Programming
PPT
Http VS. Https
PPT
Socket programming
PPT
Chapter 2 - Computer Networking a top-down Approach 7th
PPTX
Error detection and correction
PDF
Transport layer services
DOCX
Important 16 marks questions
PPTX
Chapter 3 servlet & jsp
PPTX
PPTX
PPT
Web browsers and web servers
PPTX
IP addressing and Subnetting PPT
PPTX
Multiplexing in mobile computing
PPT
Interprocess communication
PDF
Circuit Switching, Packet Switching, Virtual Circuit Networks and Datagram Ne...
PDF
9. Software Implementation
PPT
Server Side Technologies
PDF
Ddb 1.6-design issues
PDF
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
PPT
Group Communication (Distributed computing)
Socket Programming
Http VS. Https
Socket programming
Chapter 2 - Computer Networking a top-down Approach 7th
Error detection and correction
Transport layer services
Important 16 marks questions
Chapter 3 servlet & jsp
Web browsers and web servers
IP addressing and Subnetting PPT
Multiplexing in mobile computing
Interprocess communication
Circuit Switching, Packet Switching, Virtual Circuit Networks and Datagram Ne...
9. Software Implementation
Server Side Technologies
Ddb 1.6-design issues
SOLUTION MANUAL OF OPERATING SYSTEM CONCEPTS BY ABRAHAM SILBERSCHATZ, PETER B...
Group Communication (Distributed computing)
Ad

Viewers also liked (20)

PPT
chap 18 multicore computers
PPT
Multicore computers
PDF
GCM for Android
PPT
Day 5: Android User Interface [View Widgets]
PPTX
Day 9: Make Your App Location Aware using Location API
PPT
Day 4: Android: UI Widgets
PPTX
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
PPT
Day: 2 Environment Setup for Android Application Development
PDF
Lecture 2(b) Android Internals A Quick Overview
PPT
Day 3: Getting Active Through Activities
PDF
Day 1 Android: Before Getting Started
PPTX
Day 15: Working in Background
PPTX
Introduction to Android Development: Before Getting Started
PPT
Multiple Activity and Navigation Primer
PPTX
Day 15: Content Provider: Using Contacts API
PDF
Ui layout (incomplete)
PDF
Lecture 1 Session 1 Before Getting Started
PPTX
Android before getting started
PPTX
Client-Server
PDF
AndroidManifest
chap 18 multicore computers
Multicore computers
GCM for Android
Day 5: Android User Interface [View Widgets]
Day 9: Make Your App Location Aware using Location API
Day 4: Android: UI Widgets
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Day: 2 Environment Setup for Android Application Development
Lecture 2(b) Android Internals A Quick Overview
Day 3: Getting Active Through Activities
Day 1 Android: Before Getting Started
Day 15: Working in Background
Introduction to Android Development: Before Getting Started
Multiple Activity and Navigation Primer
Day 15: Content Provider: Using Contacts API
Ui layout (incomplete)
Lecture 1 Session 1 Before Getting Started
Android before getting started
Client-Server
AndroidManifest
Ad

Similar to Android Application Component: BroadcastReceiver Tutorial (20)

PPTX
Broadcast Receiver
PPT
Day 6: Android BroadcastReceiver Component
PDF
Broadcast Receiver
PPTX
Basic Intro to android(Will be updating later)
PPTX
Broadcast Receiver
PPT
Android introduction by vidya topa
PPTX
Android
PPTX
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
project presentation.pptx
PDF
Tech Talk: App Functionality (Android)
PPTX
Android session 3-behestee
PDF
[Android] Services and Broadcast Receivers
PPTX
Broadcast receiver- How Android apps listen to system-wide or app-specific ev...
PPTX
Introduction to google cloud messaging in android
PPTX
Sms and call reader
PPTX
Android Programming
PPS
Getting Started With Android Application Development [IndicThreads Mobile Ap...
PPTX
Broadcast receivers
PPTX
Android Application Components-BroadcastReceiver_Content Provider.pptx
PPT
Android Tutorial
Broadcast Receiver
Day 6: Android BroadcastReceiver Component
Broadcast Receiver
Basic Intro to android(Will be updating later)
Broadcast Receiver
Android introduction by vidya topa
Android
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
project presentation.pptx
Tech Talk: App Functionality (Android)
Android session 3-behestee
[Android] Services and Broadcast Receivers
Broadcast receiver- How Android apps listen to system-wide or app-specific ev...
Introduction to google cloud messaging in android
Sms and call reader
Android Programming
Getting Started With Android Application Development [IndicThreads Mobile Ap...
Broadcast receivers
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Tutorial

More from Ahsanul Karim (16)

PDF
Lecture 5: Storage: Saving Data Database, Files & Preferences
PDF
Lecture 3 getting active through activities
PDF
লেকচার ১ (ক)- শুরুর আগে:
PDF
Day 8: Dealing with Lists and ListViews
PDF
Day 8: Dealing with Lists and ListViews
DOC
Day 4: Activity lifecycle
PPT
Day 4: Android: Getting Active through Activities
PDF
Day 2 android internals a quick overview
PDF
Mobile Banking in Bangladesh: An Incomplete Study
PDF
List Views
PDF
Sensors in Android (old)
PDF
Day1 before getting_started
PPTX
Action Bar Sherlock tutorial
PPTX
Android Workshop: Day 1 Part 3
PPTX
Android Workshop Day 1 Part 2
PPTX
Android 1.8 sensor
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 3 getting active through activities
লেকচার ১ (ক)- শুরুর আগে:
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Day 4: Activity lifecycle
Day 4: Android: Getting Active through Activities
Day 2 android internals a quick overview
Mobile Banking in Bangladesh: An Incomplete Study
List Views
Sensors in Android (old)
Day1 before getting_started
Action Bar Sherlock tutorial
Android Workshop: Day 1 Part 3
Android Workshop Day 1 Part 2
Android 1.8 sensor

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Business Ethics Teaching Materials for college
PPTX
master seminar digital applications in india
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Basic Mud Logging Guide for educational purpose
PDF
Complications of Minimal Access Surgery at WLH
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Renaissance Architecture: A Journey from Faith to Humanism
Week 4 Term 3 Study Techniques revisited.pptx
VCE English Exam - Section C Student Revision Booklet
Business Ethics Teaching Materials for college
master seminar digital applications in india
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Types and Its function , kingdom of life
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Basic Mud Logging Guide for educational purpose
Complications of Minimal Access Surgery at WLH
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Android Application Component: BroadcastReceiver Tutorial

  • 1. Android Application DevelopmentBroadcast ReceiverAhsanul Karimahsanul.karim@sentinelbd.comSentinel Solutions Ltd.http://www.sentinelbd.com
  • 3. Android Application AnatomyActivitiesProvides User InterfaceUsually represents a Single ScreenCan contain one/more ViewsExtendsthe Activity Base classServicesNoUser InterfaceRuns in BackgroundExtends the Service Base ClassIntent/Broadcast ReceiverReceives and Reacts to broadcast IntentsNo UI but can start an ActivityExtends the BroadcastReceiver Base ClassContent ProviderMakes application data available to other appsData stored in SQLite databaseExtends the ContentProviderBase classApplication= Set of Android Components
  • 4. Broadcast ReceiversA broadcast receiver is a component that responds to system-wide Broadcast announcements. Many broadcasts originate from the system—for example, a Broadcast announcing that the screen has turned off, the battery is low, or a picture was captured or an SMS is received. Applications can also initiate broadcasts—for example, to let other Applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service/or start an activity to perform some work based on the event.
  • 5. Android Application AnatomyActivity 1 Activity 2 BroadcastReceiverServiceUIOSIntentsDirected IntentsBroadcast IntentsBIG PICTURE
  • 6. Broadcast ReceiversActivityWe’ll use a Broadcast Receiver to capture SMS receive eventWe capture the SMS receive event and launch an Activity to show the sms and give user an option to reply the SMSBroadcastReceiverOS
  • 7. Broadcast ReceiversCreate a new project BroadcastReceiverDemoA broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. In this case the intent is detected by android.provider.Telephony.SMS_RECEIVEDTo do this we’ll create a class SMSReceiver that extends BroadcastReceiver class and define the method onReceive()BroadcastReceiver
  • 8. Broadcast Receivers (Contd.)3. We also need to add SMSReceiver as receiver of a particular Intent (SMS received) which is identified by android.provider.Telephony.SMS_RECEIVEDBroadcastReceiver
  • 9. Broadcast Receivers (Contd.)4. Also we have to add permission for receiving SMSBroadcastReceiver
  • 10. Broadcast Receivers (Contd.)5. Now we run the application6. Now we use emulator control to send sms
  • 11. Receiving SMSBundle bundle = intent.getExtras(); SmsMessage[] msgs = null;String str = "";String address="";if (bundle != null){//---retrieve the SMS message received---Object[] pdus = (Object[]) bundle.get("pdus");msgs = new SmsMessage[pdus.length];for (int i=0; i<msgs.length; i++) {msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); str += "SMS from " + msgs[i].getOriginatingAddress(); str += " :";str += msgs[i].getMessageBody().toString();str += "\n"; address=msgs[i].getOriginatingAddress();Toast.makeText(context, str, Toast.LENGTH_LONG).show(); }
  • 12. Sending SMS1. Add permission in menifest.xml2. We add the following code for sending SMS from anywhere of our application
  • 13. ExerciseWe’ll create a replica of SMS application of AndroidApplication will have a basic TabActivity with 3 tabs (Activities)Send- will give user option to send sms (2 input fields for number and text)All sent SMS will be saved in databaseInbox- (List Activity) which will fetch all received SMS from databaseSent- (ListActivity) which will fetch all sent SMSA broadcast receiver which will receive SMS and save them to database