SlideShare a Scribd company logo
1 of 13
Android Application Development Broadcast Receiver Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
Application Building Blocks
Android Application Anatomy Activities Provides User Interface Usually represents a Single Screen Can contain one/more Views Extendsthe Activity Base class Services NoUser Interface Runs in Background Extends the Service Base Class Intent/Broadcast Receiver Receives and Reacts to broadcast Intents No UI but can start an Activity Extends the BroadcastReceiver Base Class Content Provider Makes application data available to other apps Data stored in SQLite database Extends the ContentProviderBase class Application= Set of Android Components
Broadcast Receivers A 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 Anatomy Activity 1  Activity 2  BroadcastReceiver Service UI OS Intents Directed Intents Broadcast Intents BIG PICTURE
Broadcast Receivers Activity We’ll use a Broadcast Receiver to capture SMS receive event We capture the SMS receive event and launch an Activity to show the sms and give user  an option to reply the SMS BroadcastReceiver OS
Broadcast Receivers Create a new project BroadcastReceiverDemo 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 += "";                     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 Application 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 database Inbox- (List Activity) which will fetch all received SMS from database Sent- (ListActivity) which will fetch all sent SMS A broadcast receiver which will receive SMS and save them to database

More Related Content

What's hot

Introduction to android
Introduction to androidIntroduction to android
Introduction to androidzeelpatel0504
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecturedeepakshare
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application DevelopmentBenny Skogberg
 
Android application-component
Android application-componentAndroid application-component
Android application-componentLy Haza
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.netSHADAB ALI
 
Introduction to Mobile Application Development
Introduction to Mobile Application DevelopmentIntroduction to Mobile Application Development
Introduction to Mobile Application DevelopmentTharindu Dassanayake
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android Ranjith Kumar
 
Introduction to Mobile Development
Introduction to Mobile DevelopmentIntroduction to Mobile Development
Introduction to Mobile DevelopmentPragnesh Vaghela
 
Android app development
Android app developmentAndroid app development
Android app developmentTanmoy Roy
 
Front-End Web Development
Front-End Web DevelopmentFront-End Web Development
Front-End Web DevelopmentYash Sati
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
Cross platform mobile application devlopment
Cross platform mobile application devlopmentCross platform mobile application devlopment
Cross platform mobile application devlopmentPrabhat gangwar
 
web service technologies
web service technologiesweb service technologies
web service technologiesYash Darak
 
Android Automotive
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys inc.
 
CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manualpkaviya
 

What's hot (20)

SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
Android application-component
Android application-componentAndroid application-component
Android application-component
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
Introduction to Mobile Application Development
Introduction to Mobile Application DevelopmentIntroduction to Mobile Application Development
Introduction to Mobile Application Development
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android
 
Introduction to Mobile Development
Introduction to Mobile DevelopmentIntroduction to Mobile Development
Introduction to Mobile Development
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Android app development
Android app developmentAndroid app development
Android app development
 
DOT Net overview
DOT Net overviewDOT Net overview
DOT Net overview
 
Front-End Web Development
Front-End Web DevelopmentFront-End Web Development
Front-End Web Development
 
React native
React nativeReact native
React native
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Cross platform mobile application devlopment
Cross platform mobile application devlopmentCross platform mobile application devlopment
Cross platform mobile application devlopment
 
App development
App developmentApp development
App development
 
web service technologies
web service technologiesweb service technologies
web service technologies
 
Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manual
 

Viewers also liked

chap 18 multicore computers
chap 18 multicore computers chap 18 multicore computers
chap 18 multicore computers Sher Shah Merkhel
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIAhsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAhsanul Karim
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentAhsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedAhsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul Karim
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIAhsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting startedAhsanul Karim
 

Viewers also liked (20)

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

Similar to Android Application Component: BroadcastReceiver Tutorial

MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentAhsanul Karim
 
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 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
 
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
 
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinSend Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinShahRushika
 
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 : a linux-based mobile operating system
Android : a linux-based mobile operating systemAndroid : a linux-based mobile operating system
Android : a linux-based mobile operating systemClément Escoffier
 
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
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Khaled Anaqwa
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1Utkarsh Mankad
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidDenis Minja
 

Similar to Android Application Component: BroadcastReceiver Tutorial (20)

Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
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
 
Broadcast receivers
Broadcast receiversBroadcast receivers
Broadcast receivers
 
Android
AndroidAndroid
Android
 
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
 
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinSend Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
 
Android introduction by vidya topa
Android introduction by vidya topaAndroid introduction by vidya topa
Android introduction by vidya topa
 
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 : a linux-based mobile operating system
Android : a linux-based mobile operating systemAndroid : a linux-based mobile operating system
Android : a linux-based mobile operating system
 
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
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
Unit2
Unit2Unit2
Unit2
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1
 
Android sensor
Android sensorAndroid sensor
Android sensor
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 

More from Ahsanul 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
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overviewAhsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyAhsanul Karim
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)Ahsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorialAhsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Ahsanul Karim
 

More from Ahsanul Karim (16)

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
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
 
List Views
List ViewsList Views
List Views
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 

Android Application Component: BroadcastReceiver Tutorial

  • 1. Android Application Development Broadcast Receiver Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 3. Android Application Anatomy Activities Provides User Interface Usually represents a Single Screen Can contain one/more Views Extendsthe Activity Base class Services NoUser Interface Runs in Background Extends the Service Base Class Intent/Broadcast Receiver Receives and Reacts to broadcast Intents No UI but can start an Activity Extends the BroadcastReceiver Base Class Content Provider Makes application data available to other apps Data stored in SQLite database Extends the ContentProviderBase class Application= Set of Android Components
  • 4. Broadcast Receivers A 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 Anatomy Activity 1 Activity 2 BroadcastReceiver Service UI OS Intents Directed Intents Broadcast Intents BIG PICTURE
  • 6. Broadcast Receivers Activity We’ll use a Broadcast Receiver to capture SMS receive event We capture the SMS receive event and launch an Activity to show the sms and give user an option to reply the SMS BroadcastReceiver OS
  • 7. Broadcast Receivers Create a new project BroadcastReceiverDemo 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 += ""; 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 Application 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 database Inbox- (List Activity) which will fetch all received SMS from database Sent- (ListActivity) which will fetch all sent SMS A broadcast receiver which will receive SMS and save them to database