Broadcast Receiver
Upcoming SlideShare
Loading in...5
×
 

Broadcast Receiver

on

  • 887 views

Android Broadcast Receiver - presented at beginner level workshop conducted by HasGeek

Android Broadcast Receiver - presented at beginner level workshop conducted by HasGeek

Statistics

Views

Total Views
887
Views on SlideShare
887
Embed Views
0

Actions

Likes
0
Downloads
91
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Broadcast Receiver Broadcast Receiver Presentation Transcript

  • 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)