SlideShare a Scribd company logo
1 of 14
Android application development 
Broadcast 
Receiver
Application Building Blocks 
• UI Component Typically 
Corresponding to one screen. 
Activity 
• Responds to notifications or status 
changes. Can wake up your process. 
IntentReceiver 
• Faceless task that runs in the 
background. 
Service 
ContentProvider • Enable applications to share data.
Android Application Anatomy 
Activities 
1. Provides User Interface 
2. Usually represents a Single Screen 
3. Can contain one/more Views 
4. Extends the Activity Base class 
Services 
1. No User Interface 
2. Runs in Background 
3. Extends the Service Base Class 
Application= Set of Android Components 
Content Provider 
1. Makes application data available 
to other apps 
2. Data stored in SQLite database 
3. Extends the ContentProvider 
Base class 
Intent/Broadcast Receiver 
1. Receives and Reacts to broadcast 
Intents 
2. No UI but can start an Activity 
3. Extends the BroadcastReceiver 
Base Class
Broadcast Receivers 
1. A broadcast receiver is a component that responds to system-wide 
Broadcast announcements. 
2. 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. 
3. 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. 
4. 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. 
5. 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 Anatomy 
UI 
Activity 1 
Service 
Activity 2 
BroadcastReceiver 
OS 
Intents 
1. Directed Intents 
2. Broadcast Intents 
BIG PICTURE
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
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
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
Broadcast Receivers (Contd.) 
4. Also we have to add permission for receiving SMS 
BroadcastReceiver
Broadcast Receivers (Contd.) 
5. Now we run the application 
6. Now we use emulator control to send sms
Receiving SMS 
Bundle 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 SMS 
1. Add permission in menifest.xml 
2. We add the following code for sending SMS from anywhere of our application
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 
2. Inbox- (List Activity) which will fetch all received SMS from 
database 
3. Sent- (ListActivity) which will fetch all sent SMS 
2. A broadcast receiver which will receive SMS and save them to 
database
Thank You.

More Related Content

What's hot

Android application structure
Android application structureAndroid application structure
Android application structureAlexey Ustenko
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferencesAjay Panchal
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Androidma-polimi
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development pptsaitej15
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Ahsanul Karim
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Maps in android
Maps in androidMaps in android
Maps in androidSumita Das
 
Eclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONEclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONAYESHA JAVED
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentEric Cattoir
 

What's hot (20)

Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferences
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Android
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
android activity
android activityandroid activity
android activity
 
Maps in android
Maps in androidMaps in android
Maps in android
 
Eclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATIONEclipse introduction IDE PRESENTATION
Eclipse introduction IDE PRESENTATION
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 

Viewers also liked

Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversJagdish Gediya
 
Android BroadcastReceiver - How to start a service using BroadcastReceiver
Android BroadcastReceiver - How to start a service using BroadcastReceiverAndroid BroadcastReceiver - How to start a service using BroadcastReceiver
Android BroadcastReceiver - How to start a service using BroadcastReceiverSriSankeerth Reddy
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in AndroidPerfect APK
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAhsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesAhsanul Karim
 

Viewers also liked (6)

Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android BroadcastReceiver - How to start a service using BroadcastReceiver
Android BroadcastReceiver - How to start a service using BroadcastReceiverAndroid BroadcastReceiver - How to start a service using BroadcastReceiver
Android BroadcastReceiver - How to start a service using BroadcastReceiver
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in Android
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
 
Android Services
Android ServicesAndroid Services
Android Services
 

Similar to Broadcast Receiver

Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentAhsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul Karim
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorialmaamir farooq
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorialmaamir farooq
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callmaamir farooq
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxKNANTHINIMCA
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1Utkarsh Mankad
 
Android App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsAndroid App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsDiego Grancini
 
Android Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolAndroid Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolFatih Özlü
 
Architecture your android_application
Architecture your android_applicationArchitecture your android_application
Architecture your android_applicationMark Brady
 
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)TECOS
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Android Trainning Session 2
Android Trainning  Session 2Android Trainning  Session 2
Android Trainning Session 2Shanmugapriya D
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 

Similar to Broadcast Receiver (20)

Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorial
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone call
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptx
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1
 
Android App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgetsAndroid App Development - 13 Broadcast receivers and app widgets
Android App Development - 13 Broadcast receivers and app widgets
 
Android Implementation using MQTT Protocol
Android Implementation using MQTT ProtocolAndroid Implementation using MQTT Protocol
Android Implementation using MQTT Protocol
 
Android
AndroidAndroid
Android
 
How to build typing indicator in a Chat app
How to build typing indicator in a Chat appHow to build typing indicator in a Chat app
How to build typing indicator in a Chat app
 
Architecture your android_application
Architecture your android_applicationArchitecture your android_application
Architecture your android_application
 
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)
 
MAD Unit 6.pptx
MAD Unit 6.pptxMAD Unit 6.pptx
MAD Unit 6.pptx
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
Android Trainning Session 2
Android Trainning  Session 2Android Trainning  Session 2
Android Trainning Session 2
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 

More from nationalmobileapps (17)

Fragment
Fragment Fragment
Fragment
 
Android Location Api
Android Location ApiAndroid Location Api
Android Location Api
 
Play Store
Play StorePlay Store
Play Store
 
GCM (push notification)
GCM (push notification)GCM (push notification)
GCM (push notification)
 
Android Sensor
Android SensorAndroid Sensor
Android Sensor
 
Ad Mob
Ad MobAd Mob
Ad Mob
 
Google Map V2
Google Map V2Google Map V2
Google Map V2
 
Database
DatabaseDatabase
Database
 
Activity & Shared Preference
Activity & Shared PreferenceActivity & Shared Preference
Activity & Shared Preference
 
Intent
IntentIntent
Intent
 
Support Multiple Screen
Support Multiple ScreenSupport Multiple Screen
Support Multiple Screen
 
Listview
ListviewListview
Listview
 
Android UI
Android UIAndroid UI
Android UI
 
Event Handling
Event HandlingEvent Handling
Event Handling
 
Project anatomy & hello world
Project anatomy & hello worldProject anatomy & hello world
Project anatomy & hello world
 
Mobile Application capacity building activities
Mobile Application capacity building activities Mobile Application capacity building activities
Mobile Application capacity building activities
 
Future of Smart phone in Bangladesh
Future of Smart phone in Bangladesh Future of Smart phone in Bangladesh
Future of Smart phone in Bangladesh
 

Recently uploaded

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 

Broadcast Receiver

  • 1. Android application development Broadcast Receiver
  • 2. Application Building Blocks • UI Component Typically Corresponding to one screen. Activity • Responds to notifications or status changes. Can wake up your process. IntentReceiver • Faceless task that runs in the background. Service ContentProvider • Enable applications to share data.
  • 3. Android Application Anatomy Activities 1. Provides User Interface 2. Usually represents a Single Screen 3. Can contain one/more Views 4. Extends the Activity Base class Services 1. No User Interface 2. Runs in Background 3. Extends the Service Base Class Application= Set of Android Components Content Provider 1. Makes application data available to other apps 2. Data stored in SQLite database 3. Extends the ContentProvider Base class Intent/Broadcast Receiver 1. Receives and Reacts to broadcast Intents 2. No UI but can start an Activity 3. Extends the BroadcastReceiver Base Class
  • 4. Broadcast Receivers 1. A broadcast receiver is a component that responds to system-wide Broadcast announcements. 2. 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. 3. 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. 4. 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. 5. 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 Anatomy UI Activity 1 Service Activity 2 BroadcastReceiver OS Intents 1. Directed Intents 2. Broadcast Intents BIG PICTURE
  • 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
  • 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
  • 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
  • 9. Broadcast Receivers (Contd.) 4. Also we have to add permission for receiving SMS BroadcastReceiver
  • 10. Broadcast Receivers (Contd.) 5. Now we run the application 6. Now we use emulator control to send sms
  • 11. Receiving SMS Bundle 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 SMS 1. Add permission in menifest.xml 2. We add the following code for sending SMS from anywhere of our application
  • 13. 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 2. Inbox- (List Activity) which will fetch all received SMS from database 3. Sent- (ListActivity) which will fetch all sent SMS 2. A broadcast receiver which will receive SMS and save them to database