Download Android-Broadcast Receiver

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
International Journal of Emerging Technology and Advanced Engineering
Website: www.ijetae.com (ISSN 2250-2459, ISO 9001:2008Certified Journal,, Volume 3, Special Issue 4, March 2013)
An Event Organized by
Parvara Rural Education Society, Sir Visvesvaraya Institute of Technology, Nashik, Maharashtra, INDIA.
Android-Broadcast Receiver
Prof. K.N Shedge1, Mr. Siddharth Pathak2, Prof. S.M. Rokade3
1
2,3
CSE, Pune University, SVIT, Nashik, India
Sir Vivesvraya Institute of Technology, Chincholi, Nashik
1
[email protected]
[email protected]
2
All broadcast receivers extend the BroadcastReceiver
base class. Unlike service component the broadcast
receiver doesn't posses any sort of user interface;ratherit
may start a new activity in response to the message it
receives or it may alertthe user through Notification
Manager.Notification Manager allows application to
notify users about events that take place. The notification
can be inform of vibration,flashing LEDs of mobile
device, playing specic sound against specific event, or
could be an icon (persistently displayed into the status
bar).[1]
Abstract-Android is a comprehensive open source
platform designed for mobile devices. it is a truly open
platform that is separating hardware from software that
runs on it. This allows for a much larger number of devices
to run same applications and creates a much richer
ecosystem for developers and consumers to enjoy. Android
is a purpose-built platform for mobile devices. Android was
designed to run on all sorts of physical devices.Android
applications are written in the Java programming language.
The Android SDK tools compile the code—along with any
data and resource files—into an Android package, an
archive file with an .apk suffix. All the code in a single .apk
file is considered to be one application and is the file that
Android-powered devices use to install the application. A
broadcast receiver is an main building block of Android
OS.A broadcast receiver is an Android component which
allows to register for system or application events. All
registered receivers for an event will be notified by Android
once this event happens.
II. T HEORY
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.
Broadcast Receiver is 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
Broadcast Receiver OS.
I. INTRODUCTION
Broadcast receiver is another basic component of
Android application. It is use to receive the broadcast
announcements and react according to the arise
situation.Normally
system
makes
broadcast
announcements, such as time zone has changed,Picture
has been captured, language preferences have changed,
or battery power is low. Same as system code,
application can also initiate broadcast and broadcast
receivers (contained by applications) may react to it, if
needed so. Suppose, browser generate broadcast
announcement that the requested download has been
complete and it's now available for other applications to
use. Application can have more than one broadcast
receivers to receive multiple broadcast announcements
simultaneously.
33
International Journal of Emerging Technology and Advanced Engineering
Website: www.ijetae.com (ISSN 2250-2459, ISO 9001:2008Certified Journal,, Volume 3, Special Issue 4, March 2013)
An Event Organized by
Parvara Rural Education Society, Sir Visvesvaraya Institute of Technology, Nashik, Maharashtra, INDIA.
Services are useful for actions that we want to
make sure performs for a while, regardless of
what is on the screen. For example, you may
want to have your music player play music even
as you are flipping between other applications.
4) Content Providers- Content Providers are
interfaces for sharing data between applications.
Android by default runs each application in its
own sandbox so that all data that belongs to an
application is totally isolated from other
applications on the system. While small
amounts of data can be passed between
applications via Intents, Content Providers are
much better suited for sharing persistent data
between possibly large datasets.
Broadcast receivers are Android‟s key part of any
apps, more precisely is an observer pattern which
basically works as a guard to your app.Applications
(known as publishers) can generate broadcasts to simply
send events not knowing who, if anyone, will get them.
Receivers (known as subscribers) that want the
information subscribe to specific messages via filters. If
the message matches a filter, the subscriber is activated
(if it‟s not already running) and notified of the message.
A BroadcastReceiver is a piece of code to which an
app subscribes in order to get notified when an action
happens. That action is in a form of an intent broadcast.
When the right intent is fired, the receiver wakes up and
executes. The "wakeup" happens in form of a
onReceive() callback method .Boot Receiver: we usually
creates boot receiver to get updates from server, its an
part of Broadcast Receivers to get update even app is not
in
active
state.We
create
BootReceiver
by
subclassingBroadcastReceiver, the base class for all
receivers.
III.
IV. T HE ANDROID MANIFEST FILE
Before we go in detail of Broadcast Receiver it‟s very
important to know aboutAndroidManifestfile. Your
application must declare all its components in this
file.Before the Android system can start an application
component, the system must know that the component
exists by reading the application's AndroidManifest.xml
file (the "manifest" file). Your application must declare
all its components in this file, which must be at the root
of the application project directory.
ANDROID BUILDING BOLCK
Main building blocks are components that you use as
an application developer to build Android apps. They are
the conceptual items that you put together to create a
Apps.
The manifest does a number of things in addition to
declaring the application's components, such as:
Android building blocks make it easy to break them
down into conceptual units so that you can work on them
independently, and can also easily put them together into
a complete package.Main building blocks are as follows:
1) Identify any user permissions the application
requires, such as Internet access or read-access
to the user's contacts.
2) Declare the minimum API Level required by the
application, based on which APIs the
application uses.
3) Declare hardware and software features used or
required by the application, such as a camera,
bluetooth services, or a multitouch screen.
4) API libraries the application needs to be linked
against (other than the Android framework
APIs), such as the Google Maps library.
1) Activities-An activity is usually a single screen
that the user sees on the device at one time. An
application typically has multiple activities and
the user flips back and forth among them. As
such, activities are the most visible part of your
application.
2) Intents- Intents are messages that are sent
among major building blocks. They trigger an
activity to start up, a service to start or stop, or
are simply broadcasts. Intents are asynchronous,
meaning the code that is sending them doesn‟t
have to wait for them to be completed.
3) Services- Services run in the background and
don‟t have any user interface components. They
can perform the same actions as Activities
without any user interface.
V. STRUCTURE OF BROADCAST RECEIVER
A broadcast receiver is a dormant component of the
Android system. Only an Intent (for which it is
registered) can bring it into action. The Broadcast
Receiver‟s job is to pass a notification to the user, in case
a specific event occurs.
34
International Journal of Emerging Technology and Advanced Engineering
Website: www.ijetae.com (ISSN 2250-2459, ISO 9001:2008Certified Journal,, Volume 3, Special Issue 4, March 2013)
An Event Organized by
Parvara Rural Education Society, Sir Visvesvaraya Institute of Technology, Nashik, Maharashtra, INDIA.
Using a Broadcast Receiver, applications can register
for a particular event. Once the event occurs, the system
will notify all the registered applications.
You have an important social gathering to attend.
Because of your shoddy memory, you have requested
your friend to notify you a day before the event. Now,
because you have „registered‟ for the said friend‟s help,
you will get a reminder from him as discussed. This is
roughly how the Broadcast Receiver works.
The two major classes of broadcasts are:
A. Ordered Broadcasts:
These broadcasts are synchronous, and therefore
follow a specific order. The order is defined using
android: priority attribute. The receivers with greater
priority would receive the broadcast first. In case there
are receivers with same priority levels, the broadcast
would not follow an order. Each receiver (when it
receives the broadcast) can either pass on the notification
to the next one, or abort the broadcast completely. On
abort, the notification would not be passed on to the
receivers next in line.
B. Normal Broadcasts:
Normal broadcasts are not orderly. Therefore, the
registered receivers often run all at the same time. This is
very efficient, but the Receivers are unable to utilize the
results.
For example,a Broadcast receiver triggers battery Low
notification that you see on your mobile screen.Other
instances caused by a Broadcast Receiver are new friend
notifications, new friend feeds, new message etc. on your
Facebook app.
VI. IMPLEMENTATION OF BROADCAST
In fact, you see broadcast receivers at work all the
time. Notifications like incoming messages, WiFi
Activated/Deactivated message etc. are all real-time
announcements of what is happening in the Android
system and the applications.
RECEIVER
When implementing a broadcast receiver you have to
do two steps:
A. You have to create a subclass of Android’s
BroadcastReceiver:
Every broadcast receiver must subclass Android‟s
BroadcastReceiver. This base class is abstract, which
means that you have to provide an implementation of the
abstract methodonReceive().
B. You have to implement the onReceive() method:
In order for the notification to be sent, an onReceive()
method has to be implemented. Whenever the event for
which the receiver is registered occurs, onReceive() is
called.
35
International Journal of Emerging Technology and Advanced Engineering
Website: www.ijetae.com (ISSN 2250-2459, ISO 9001:2008Certified Journal,, Volume 3, Special Issue 4, March 2013)
An Event Organized by
Parvara Rural Education Society, Sir Visvesvaraya Institute of Technology, Nashik, Maharashtra, INDIA.
For instance, in case of battery low notification, the
Whenever you want to know about system wide
receiver
is
registered
to
events you need to implement and register a
Intent.ACTION_BATTERY_LOW event. As soon as the
BroadcastReceiver. From then on your receiver gets
battery level falls below the defined level, this
notifications whenever the system event, for which it is
onReceive() method is called.
registered, occurs.
Following are the two arguments of the onReceive()
method:
REFERENCES
[1]
1.
2.
Context: This is used to access additional
information, or to start services or activities.
Intent: The Intent object is used to register the
receiver.
There are two ways to register a Broadcast Receiver;
one is Static and the other Dynamic.
[2]
Security
Engineering
Research
Group,Instituteof
Management SciencesPeshawar,Pakistan “Analysis report
on
Android
ApplicationFramework
and
existing
SecurityArchitecture”
http://serg.imsciences.edu.pk,
February 2010
Pro Android 4 by SatyaKomatineni; Dave MacLean
[3]
[4]
Learning Android by MarkoGargenta
Do Androids Dream of Electric Sheep ByPhilip K. Dick
[5]
MachigarOngtang, Stephen McLaughlin, William Enck and
Patrick
1.Static: Use <receiver> tag in your Manifest file.
(AndroidManifest.xml)
2.Dynamic: Use Context.registerReceiver ()
method to dynamically register an instance.
McDaniel.Semantically rich
application-centric
security
in
android.Available:www.patrickmcdaniel.org/pubs/acsac09a.
pdf.
[6]
VII. BROADCAST RECEIVER SECURITY
Patch for android security aw released by google and tmobile.
As the broadcast receivers have a global work-space,
security is very important concern here. If you do not
define the limitations and filters for the registered
receivers, other applications can abuse them. Here are a
few limitations that might help:
1)
2)
3)
Available:https://www.isecpartners.com/files/iSEC_Securin
g_Android_Apps.pdf
[7]
Whenever you publish a receiver in your
application‟s manifest, make it unavailable to
external applications by using android:
exported=”false”. You might think that specifying
Intent filters while publishing the receiver would
do the task for you, when in reality they are not
enough.
When you send a broadcast, it is possible for
the external applications too to receive them. This
can be prevented by specifying a few limitations.
Similarly, when you register your receiver
using registerReceiver, any application may send
it broadcasts. This can be prevented using
permissions as well.
VIII. CONCLUSION
A broadcast receiver is an Android component which
allows to register for system or application events. All
registered receivers for an event will be notified by
Android once this event happens Broadcast receivers are
Android‟s key part of any apps, more precisely is an
observer pattern which basically works as a guard to your
app.
36
what
is
android.
Available
http://developer.android.com/guide/basics/what-isandroid.html
at: