Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.

Slides:



Advertisements
Similar presentations
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Advertisements

BroadcastReceiver.  Base class for components that receive and react to events  Events are represented as Intent objects  Intents received as parameter.
Android 101 Application Fundamentals January 29, 2010.
Cosc 5/4730 Android SMS. A note first Depending on the API level, an import changes because of a deprecated API 3 uses – import android.telephony.gsm.SmsManager;
System broadcasts and services. System broadcast events. EventDescription Intent.ACTION_BOOT_COMPLETEDBoot completed. Requires the android.permission.RECE.
Mobile Programming Pertemuan 6 Presented by Mulyono Poltek NSC Surabaya.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Broadcast Receiver Android Club Agenda Broadcast Receiver Widget.
Integrating with Android Services. Introduction  Android has numerous built-in functionality that can be called from within your applications  SMS/MMS.
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
Android ICC Part II Inter-component communication.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
Mobile Programming Lecture 6
DUE Hello World on the Android Platform.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
Android - Broadcast Receivers
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Google map v2.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
Cosc 4735 Nougat API 24+ additions.
Workshop by T.Naveen sai kumar.
Lab7 – Appendix.
Android Programming - Features
Mobile Software Development for Android - I397
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Lecture 2: Android Concepts
Android Application Development 1 6 May 2018
CS499 – Mobile Application Development
Broadcast receivers.
CS371m - Mobile Computing Services and Broadcast Receivers
Adapting to Display Orientation
Android Introduction Hello World.
Android Notifications
XML Mihail L. Sichitiu.
Messaging Unit-4.
Cleveland State University
Mobile Computing With Android ACST 4550 XML and the Android GUI
Mobile Software Development for Android - I397
Android Introduction Camera.
Mobile Device Development
Anatomy of an Android Application
Android Programming Lecture 9
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
Application Fundamentals
CIS 470 Mobile App Development
Many thanks to Jun Bum Lim for his help with this tutorial.
CMPE419 Mobile Application Development
Android Topics Android Activity Lifecycle and Experiment Toast
HNDIT2417 Mobile Application Development
Activities and Intents
Android Notifications
Android Developer Fundamentals V2 Lesson 5
CIS 470 Mobile App Development
Application Fundamentals
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Chapter 5 Your Second Activity.
Mobile Programming Broadcast Receivers.
Presentation transcript:

Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast is delivered as a intent object It extends the class BroadcastReceiver You will be notified about the events after registering. It plays a role of “No UI gateway” to do some small work such as starting a service or activity based on the received notice/event Broadcast originates from the system as well as applications. Ex: Instance for broadcast originating from the system: ‘low battery notification’, SMS received Ex: Application level is, like when you download an mp3 file, Mp3 player gets notified about it, and gets added to player list. For this action to take place, mp3 player has to register for this event.

Two ways to register Android broadcastreceiver One is static way in which the broadcast receiver is registered in an android application via AndroidManifest.xml file. Another way of registering the broadcast receiver is dynamic, which is done using Context.registerReceiver() method. Dynamically registered broadcast receivers can be unregistered using Context.unregisterReceiver() method.

<. xml version="1. 0" encoding="utf-8" <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.broadcastreceiverdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.broadcastreceiverdemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="BroadCastReceiver_Name" > <action android:name="Event_Name" > </action> </receiver> </application> </manifest>

onReceive() Create your Broadcast receiver and Implement onReceive() method of BroadcastReceiver abstract class Whenever the event occurs Android calls the onReceive() method on the registered broadcast receiver. For example, if you register for ACTION_POWER_CONNECTED event then whenever power got connected to the device, your broadcast receiver’s onReceive() method will be invoked. The onReceive() method takes two arguments. Ubli class myReceive extends BroadcastReceiver{ public void onReceive(Context context, Intent intent){ ToDo something }} Context is used to start services or activities and the intent is object with the action you used to register your receiver.

Register your Broadcast Receiver The broadcast receiver can statically be registered via AndroidManifest.xml as said earlier. The element is used to specify the event the receiver should react to. So whenever this event ‘MyBroadcast’ occurs MyBroadcastReceiver’s onReceive() method will be invoked. As soon as the onReceive() method is finished, your BroadcastReceiver terminates.

Sample Application http://www.compiletimeerror.com/2013/03/android-broadcast-receiver-in-detail.html#.VNyySvnF8qR http://examples.javacodegeeks.com/android/core/content/broadcastreceiver/android-broadcast-receivers-example/

REGISTER THE BROADCAST RECEIVER PROGRAMMATICALLY/DYNAMICALLY BroadcastReceiver myReceiver=new MyBroadcastReceiver(); registerReceiver( this.myReceiver, new IntentFilter("MyBroadcast"));