SlideShare a Scribd company logo
Android Application Development
                        Broadcast Receiver


          Click to edit Master subtitle style




                                                             Ahsanul Karim
                                                ahsanul.karim@sentinelbd.com
                                                     Sentinel Solutions Ltd.
                                                   http://www.sentinelbd.com
5/21/11
Application Building Blocks
ly Corresponding to one screen.




     IntentReceiver Service          Activity      ContentProvider




ns or status changes.that runs in up your process. applications to share data.
       Faceless task Can wake the background.
                                           Enable




     5/21/11
Android Application Anatomy
                      Activities                                     Services
            1.    Provides User Interface                      1.   No User Interface
           2.    Usually represents a Single              2.      Runs in Background
                           Screen
                                                3.             Extends the Service Base
     3.         Can contain one/more Views                                Class
      4.         Extends the Activity Base
                           class
                            Application= Set of Android Components

      Intent/Broadcast Receiver                                 Content Provider
       1.    Receives and Reacts to                  1.        Makes application data
               broadcast Intents                             available to other apps
          2.  No UI but can start an            2.        Data stored in SQLite database
                     Activity                    3.        Extends the ContentProvider
                                                                    Base class
3.      Extends the BroadcastReceiver
     5/21/11       Base Class
Broadcast Receivers
1.   A broadcast receiver is a component that responds to system-wide
Broadcast announcements.
1.   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.
1.   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.
1.   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.
1.   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/21/11
Android Application Anatomy


                      Activity 1             Activity 2

     UI



      Service                       BroadcastReceiver



           Intents
           1.   Directed Intents
           2.   Broadcast Intents                         OS

                   BIG PICTURE
 5/21/11
Broadcast Receivers
1. We’ll use a Broadcast Receiver to capture SMS receive event
2. We capture the SMS receive event and launch an Activity to show the sms and give user
an option to reply the SMS
                                                   Activity




                 OS                         BroadcastReceiver




     5/21/11
Broadcast Receivers
 1. Create a new project BroadcastReceiverDemo
 2. A 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_RECEIVED

 To do this we’ll create a class SMSReceiver that extends BroadcastReceiver class and
    define the method onReceive()




                                             BroadcastReceiver




      5/21/11
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_RECEIVED




                                             BroadcastReceiver




  5/21/11
Broadcast Receivers (Contd.)
 4. Also we have to add permission for receiving SMS




                                             BroadcastReceiver




  5/21/11
Broadcast Receivers (Contd.)
 5. Now we run the application
 6. Now we use emulator control to send sms




  5/21/11
Sending SMS
  1. Add permission in menifest.xml



  2. We add the following code for sending SMS from anywhere of our application




  5/21/11
Exercise

 We’ll create a replica of SMS application of Android

 1.   Application will have a basic TabActivity with 3 tabs (Activities)
       1.  Send- will give user option to send sms (2 input fields for number and text)
 All sent SMS will be saved in database
       1.  Inbox- (List Activity) which will fetch all received SMS from database
       2.  Sent- (ListActivity) which will fetch all sent SMS
 1.   A broadcast receiver which will receive SMS and save them to database




      5/21/11

More Related Content

PPTX
Android 1.8 sensor
PDF
Lecture 3 getting active through activities
PDF
Lecture 2(b) Android Internals A Quick Overview
PDF
Lecture 1 Session 1 Before Getting Started
PDF
Sensors in Android (old)
PDF
Day 2 android internals a quick overview
PPTX
Android before getting started
PPTX
Android application-component
Android 1.8 sensor
Lecture 3 getting active through activities
Lecture 2(b) Android Internals A Quick Overview
Lecture 1 Session 1 Before Getting Started
Sensors in Android (old)
Day 2 android internals a quick overview
Android before getting started
Android application-component

What's hot (20)

PPTX
Android 101
PPT
Android activity, service, and broadcast recievers
PDF
AndroidManifest
PPTX
PDF
Marakana Android User Interface
PDF
Android development-tutorial
DOC
Mobile testing android
PDF
What’s new in Xcode 8? – Future of Native App Development Opportunities
PPTX
Android intents, notification and broadcast recievers
PDF
android level 1
PPSX
Android architecture components
PDF
Android session 2
PPT
Google Android
PDF
Android session 1
PPTX
Android Life Cycle
PDF
Android session 3
PDF
Android Capstone Project, Final Deliverable Documentation
PPTX
Create your First Watchkit App
PDF
MobileAppDev Handout#2
PDF
Android notification
Android 101
Android activity, service, and broadcast recievers
AndroidManifest
Marakana Android User Interface
Android development-tutorial
Mobile testing android
What’s new in Xcode 8? – Future of Native App Development Opportunities
Android intents, notification and broadcast recievers
android level 1
Android architecture components
Android session 2
Google Android
Android session 1
Android Life Cycle
Android session 3
Android Capstone Project, Final Deliverable Documentation
Create your First Watchkit App
MobileAppDev Handout#2
Android notification
Ad

Viewers also liked (16)

PPTX
Mcq peresentation
PPTX
Day 9: Make Your App Location Aware using Location API
PPTX
Action Bar Sherlock tutorial
PPTX
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
PDF
Training android
PPT
Day 5: Android User Interface [View Widgets]
PDF
Day 1 Android: Before Getting Started
PPTX
Day 15: Working in Background
PPTX
Introduction to Android Development: Before Getting Started
PPT
Day 3: Getting Active Through Activities
PPT
Day: 2 Environment Setup for Android Application Development
PDF
Lecture 5: Storage: Saving Data Database, Files & Preferences
PPTX
Day 15: Content Provider: Using Contacts API
PDF
Ui layout (incomplete)
PPTX
Client-Server
PDF
GCM for Android
Mcq peresentation
Day 9: Make Your App Location Aware using Location API
Action Bar Sherlock tutorial
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Training android
Day 5: Android User Interface [View Widgets]
Day 1 Android: Before Getting Started
Day 15: Working in Background
Introduction to Android Development: Before Getting Started
Day 3: Getting Active Through Activities
Day: 2 Environment Setup for Android Application Development
Lecture 5: Storage: Saving Data Database, Files & Preferences
Day 15: Content Provider: Using Contacts API
Ui layout (incomplete)
Client-Server
GCM for Android
Ad

Similar to Day 6: Android BroadcastReceiver Component (20)

PPTX
Broadcast Receiver
PPTX
Android Application Component: BroadcastReceiver Tutorial
PDF
Android broadcast receiver tutorial
PDF
Android broadcast receiver tutorial
PPT
LA_FUNDAMENTALS OF Android_Unit I ONE.ppt
PPTX
Android : a linux-based mobile operating system
PPTX
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
Broadcast Receiver
PPTX
Beginning android
PPTX
Android application development
PPTX
Android beginners David
PPTX
Android platform
PPTX
Basic of Android App Development
PDF
Android Introduction by Kajal
PDF
04 programmation mobile - android - (db, receivers, services...)
PPTX
02. Android application development_Lec2.pptx
PPTX
UNIT5newpart1pptx__2024_11_13_09_51_59 (1).pptx
ODP
Nativa Android Applications development
PDF
Android Basic- CMC
PPT
Introduction to android
Broadcast Receiver
Android Application Component: BroadcastReceiver Tutorial
Android broadcast receiver tutorial
Android broadcast receiver tutorial
LA_FUNDAMENTALS OF Android_Unit I ONE.ppt
Android : a linux-based mobile operating system
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
Broadcast Receiver
Beginning android
Android application development
Android beginners David
Android platform
Basic of Android App Development
Android Introduction by Kajal
04 programmation mobile - android - (db, receivers, services...)
02. Android application development_Lec2.pptx
UNIT5newpart1pptx__2024_11_13_09_51_59 (1).pptx
Nativa Android Applications development
Android Basic- CMC
Introduction to android

More from Ahsanul Karim (11)

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: UI Widgets
PPT
Day 4: Android: Getting Active through Activities
PDF
Mobile Banking in Bangladesh: An Incomplete Study
PDF
List Views
PDF
Day1 before getting_started
PPTX
Android Workshop: Day 1 Part 3
PPTX
Android Workshop Day 1 Part 2
লেকচার ১ (ক)- শুরুর আগে:
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Day 4: Activity lifecycle
Day 4: Android: UI Widgets
Day 4: Android: Getting Active through Activities
Mobile Banking in Bangladesh: An Incomplete Study
List Views
Day1 before getting_started
Android Workshop: Day 1 Part 3
Android Workshop Day 1 Part 2

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
Per capita expenditure prediction using model stacking based on satellite ima...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx

Day 6: Android BroadcastReceiver Component

  • 1. Android Application Development Broadcast Receiver Click to edit Master subtitle style Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com 5/21/11
  • 2. Application Building Blocks ly Corresponding to one screen. IntentReceiver Service Activity ContentProvider ns or status changes.that runs in up your process. applications to share data. Faceless task Can wake the background. Enable 5/21/11
  • 3. Android Application Anatomy Activities Services 1. Provides User Interface 1. No User Interface 2. Usually represents a Single 2. Runs in Background Screen 3. Extends the Service Base 3. Can contain one/more Views Class 4. Extends the Activity Base class Application= Set of Android Components Intent/Broadcast Receiver Content Provider 1. Receives and Reacts to 1. Makes application data broadcast Intents available to other apps 2. No UI but can start an 2. Data stored in SQLite database Activity 3. Extends the ContentProvider Base class 3. Extends the BroadcastReceiver 5/21/11 Base Class
  • 4. Broadcast Receivers 1. A broadcast receiver is a component that responds to system-wide Broadcast announcements. 1. 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. 1. 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. 1. 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. 1. 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/21/11
  • 5. Android Application Anatomy Activity 1 Activity 2 UI Service BroadcastReceiver Intents 1. Directed Intents 2. Broadcast Intents OS BIG PICTURE 5/21/11
  • 6. Broadcast Receivers 1. We’ll use a Broadcast Receiver to capture SMS receive event 2. We capture the SMS receive event and launch an Activity to show the sms and give user an option to reply the SMS Activity OS BroadcastReceiver 5/21/11
  • 7. Broadcast Receivers 1. Create a new project BroadcastReceiverDemo 2. A 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_RECEIVED To do this we’ll create a class SMSReceiver that extends BroadcastReceiver class and define the method onReceive() BroadcastReceiver 5/21/11
  • 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_RECEIVED BroadcastReceiver 5/21/11
  • 9. Broadcast Receivers (Contd.) 4. Also we have to add permission for receiving SMS BroadcastReceiver 5/21/11
  • 10. Broadcast Receivers (Contd.) 5. Now we run the application 6. Now we use emulator control to send sms 5/21/11
  • 11. Sending SMS 1. Add permission in menifest.xml 2. We add the following code for sending SMS from anywhere of our application 5/21/11
  • 12. Exercise We’ll create a replica of SMS application of Android 1. Application will have a basic TabActivity with 3 tabs (Activities) 1. Send- will give user option to send sms (2 input fields for number and text) All sent SMS will be saved in database 1. Inbox- (List Activity) which will fetch all received SMS from database 2. Sent- (ListActivity) which will fetch all sent SMS 1. A broadcast receiver which will receive SMS and save them to database 5/21/11