SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
Broadcast Receiver
●

Broadcasts are system wide events

●

Examples
– SMS received , battery low, bluetooth,

●

Broadcast-Receiver
–

Handles these events
Broadcast Receiver
●

Cannot display User Inferace

●

Must be handled within 10 seconds

●

Can start a service for background processing
Broadcast Receiver subclass
class ........ extends BroadcastReceiver
{
onReceive( )
{
your code to handle the broadcast event
}

}
Steps
●

create subclass of BroadcastReceiver

●

onReceive()

●

Get the intent – check if it has SMS info

●

Register our receiver in manifest

●

Set the SMS permissions in manifest
Steps
●

create subclass of BroadcastReceiver

●

onReceive()

●

Register our receiver in manifest

●

Set the SMS permissions in manifest

●

Get the intent – check if it has SMS info
onReceive
String action="android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context c, Intent i) {

final Bundle bundle = i.getExtras();
if(i.getAction().equals(action))
{
Toast.makeText(c, "SMS Received", Toast.LENGTH_SHORT).show();
String msg= parseSMS(bundle);
Toast.makeText(c, msg, Toast.LENGTH_SHORT).show();
}
}
Extract SMS
●

Intent

Bundle

PDU

SMS
Extract SMS
●

Intent

Bundle

PDU

Bundle bundle = intent.getExtras();
Object[] pdusObj = bundle.get("pdus");
SmsMessage msg =
SmsMessage.createFromPdu((byte[])
pdusObj[0]);

SMS
Extract SMS
●

Intent

Bundle

PDU

SMS
Examples of broadcasts
●

Examples for system events Event Usage

●

Intent.ACTION_BATTERY_LOW

●

Intent.ACTION_BATTERY_OKAY The battery level has risen again

●

Intent.ACTION_BOOT_COMPLETED

●

Intent.ACTION_DEVICE_STORAGE_LOW Storage space on the device is getting limited

●

Intent.ACTION_DEVICE_STORAGE_OK The storage situation has improved again

●

Intent.ACTION_HEADSET_PLUG A headset was plugged in or a previously plugged headset was removed

●

Intent.ACTION_LOCALE_CHANGED

●

Intent.ACTION_MY_PACKAGE_REPLACED

●

Intent.ACTION_PACKAGE_ADDED A new app has been installed

●

Intent.ACTION_POWER_CONNECTED

●

Intent.ACTION_POWER_DISCONNECTED The device has been disconnected again

●

KeyChain.ACTION_STORAGE_CHANGED The keystore changed

●

BluetoothDevice.ACTION_ACL_CONNECTED A Bluetooth ACL connection has been established

●

●

The battery level has fallen below a threshold
Android is up and running

The user changed the language of the device
Your app has been updated

The device has been plugged in

AudioManager.ACTION_AUDIO_BECOMING_NOISY The internal audio speaker is about to be used instead
of other output means (like a headset)

Contenu connexe

Tendances

Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
Theo Jungeblut
 

Tendances (20)

Android service
Android serviceAndroid service
Android service
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Android resources
Android resourcesAndroid resources
Android resources
 
Android ui menu
Android ui menuAndroid ui menu
Android ui menu
 
Android Toast.pdf
Android Toast.pdfAndroid Toast.pdf
Android Toast.pdf
 
Notification android
Notification androidNotification android
Notification android
 
Broadcast receivers
Broadcast receiversBroadcast receivers
Broadcast receivers
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Java program structure
Java program structureJava program structure
Java program structure
 

En vedette (6)

OpenGLES Android Graphics
OpenGLES Android GraphicsOpenGLES Android Graphics
OpenGLES Android Graphics
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
Introduction to RTOS
Introduction to RTOSIntroduction to RTOS
Introduction to RTOS
 
Android - Broadcast Receiver
Android - Broadcast ReceiverAndroid - Broadcast Receiver
Android - Broadcast Receiver
 

Similaire à Broadcast Receiver

Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
Ahsanul Karim
 
MMS Parser
MMS ParserMMS Parser
MMS Parser
mamahow
 

Similaire à Broadcast Receiver (20)

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 Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in Android
 
Integrando sua app Android com Chromecast
Integrando sua app Android com ChromecastIntegrando sua app Android com Chromecast
Integrando sua app Android com Chromecast
 
Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notifications
 
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
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)
 
MMS Parser
MMS ParserMMS Parser
MMS Parser
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
Maintaining Your Code Clint Eastwood Style
Maintaining Your Code Clint Eastwood StyleMaintaining Your Code Clint Eastwood Style
Maintaining Your Code Clint Eastwood Style
 
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Air superiority for Android Apps
Air superiority for Android AppsAir superiority for Android Apps
Air superiority for Android Apps
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorialPowering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
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
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 

Plus de Arvind Devaraj

Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android Workshop
Arvind Devaraj
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
Arvind Devaraj
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
Arvind Devaraj
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier Transforms
Arvind Devaraj
 

Plus de Arvind Devaraj (20)

Deep learning for NLP and Transformer
 Deep learning for NLP  and Transformer Deep learning for NLP  and Transformer
Deep learning for NLP and Transformer
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Career hunt pitch
Career hunt pitchCareer hunt pitch
Career hunt pitch
 
Career options for CS and IT students
Career options for CS and IT studentsCareer options for CS and IT students
Career options for CS and IT students
 
Careerhunt ebook
Careerhunt ebookCareerhunt ebook
Careerhunt ebook
 
Static Analysis of Computer programs
Static Analysis of Computer programs Static Analysis of Computer programs
Static Analysis of Computer programs
 
Hyperbook
HyperbookHyperbook
Hyperbook
 
Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android Workshop
 
AIDL - Android Interface Definition Language
AIDL  - Android Interface Definition LanguageAIDL  - Android Interface Definition Language
AIDL - Android Interface Definition Language
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
Operating system
Operating systemOperating system
Operating system
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier Transforms
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006)
 
Computer Systems
Computer SystemsComputer Systems
Computer Systems
 
Computability
Computability Computability
Computability
 
Fourier Transforms
Fourier TransformsFourier Transforms
Fourier Transforms
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Broadcast Receiver

  • 1. Broadcast Receiver ● Broadcasts are system wide events ● Examples – SMS received , battery low, bluetooth, ● Broadcast-Receiver – Handles these events
  • 2. Broadcast Receiver ● Cannot display User Inferace ● Must be handled within 10 seconds ● Can start a service for background processing
  • 3. Broadcast Receiver subclass class ........ extends BroadcastReceiver { onReceive( ) { your code to handle the broadcast event } }
  • 4. Steps ● create subclass of BroadcastReceiver ● onReceive() ● Get the intent – check if it has SMS info ● Register our receiver in manifest ● Set the SMS permissions in manifest
  • 5. Steps ● create subclass of BroadcastReceiver ● onReceive() ● Register our receiver in manifest ● Set the SMS permissions in manifest ● Get the intent – check if it has SMS info
  • 6. onReceive String action="android.provider.Telephony.SMS_RECEIVED"; public void onReceive(Context c, Intent i) { final Bundle bundle = i.getExtras(); if(i.getAction().equals(action)) { Toast.makeText(c, "SMS Received", Toast.LENGTH_SHORT).show(); String msg= parseSMS(bundle); Toast.makeText(c, msg, Toast.LENGTH_SHORT).show(); } }
  • 8. Extract SMS ● Intent Bundle PDU Bundle bundle = intent.getExtras(); Object[] pdusObj = bundle.get("pdus"); SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdusObj[0]); SMS
  • 10. Examples of broadcasts ● Examples for system events Event Usage ● Intent.ACTION_BATTERY_LOW ● Intent.ACTION_BATTERY_OKAY The battery level has risen again ● Intent.ACTION_BOOT_COMPLETED ● Intent.ACTION_DEVICE_STORAGE_LOW Storage space on the device is getting limited ● Intent.ACTION_DEVICE_STORAGE_OK The storage situation has improved again ● Intent.ACTION_HEADSET_PLUG A headset was plugged in or a previously plugged headset was removed ● Intent.ACTION_LOCALE_CHANGED ● Intent.ACTION_MY_PACKAGE_REPLACED ● Intent.ACTION_PACKAGE_ADDED A new app has been installed ● Intent.ACTION_POWER_CONNECTED ● Intent.ACTION_POWER_DISCONNECTED The device has been disconnected again ● KeyChain.ACTION_STORAGE_CHANGED The keystore changed ● BluetoothDevice.ACTION_ACL_CONNECTED A Bluetooth ACL connection has been established ● ● The battery level has fallen below a threshold Android is up and running The user changed the language of the device Your app has been updated The device has been plugged in AudioManager.ACTION_AUDIO_BECOMING_NOISY The internal audio speaker is about to be used instead of other output means (like a headset)