2. About me
• Android hacker.
• Organizer, Bangalore Android User
Group ( www.blrdroid.org )
• Research Engineer at Philips R&D
3. Bangalore Android User Group ( www.BlrDroid.org)
• Largest open Android developer community in
the country and second largest in the world.
• Over 2500 members
• 19 meetups
• 3 hackathons
• Active participation in events like Droidcon,
Global Android Developer hackathon etc
4. What we will be discussing today.
Why do we How it is
What is implemented ?
GCM? need GCM?
Google Cloud Messaging
6. GCM definition
GCM stands for Google Cloud Messaging .
It is a free service that allows developers to send
data from third party servers to their applications
running on android devices
Handles queuing of messages and delivery to the
target application running on the target device.
Intended use is not to send huge amount of data to
the client device
7. Things to keep in mind
Application on the android device DOES
NOT need to be running to receive
messages.
Requires user to set up a Google account
on the device.
It is purely a routing component
There is no guaranteed delivery of
messages to the device .
8. Focus of GCM
GCM stats are
Ease of use. No available through
No quotas.
sign-up forms. the Android
Developer Console.
Rich set of new
Battery efficiency.
APIs
9. Difference between GCM and C2DM
Simple API Key from Google
APIs console page.
Sender id is the project id rather
than email address
Supports data in JSON format
and plain text
10. Difference between GCM and C2DM
Multicast message support
Multiple senders
Messages have time to live ( 0 ~
4 weeks ) eg. Expiring invitations
Payload up to 4kb
12. The need to use GCM
Client server architecture is the most
common architecture .
Most application do all the heavy lifting and
processing at the servers and then use the
processed data within the applications .
Scalability & extensibility
More computing power
13. The need to use GCM
Background process polling server for
information at regular intervals is a bad
design
Battery performance
System resource usage ( memory , CPU )
Complicated coding
Application does not need to be running in
the background for receiving data messages.
Lower cost and better tracking than SMS.
14. The need to use GCM
Less coding required
Not need to worry about queuing of
messages
Differed delivery
Simpler application flow
15. The need to use GCM
In a nutshell it makes application design
much more simple, improves battery
performance and makes better use of
system resources .
17. Major components
Your application server
GCM servers
Mobile device
18. Typical sequence of events
The application
server sends a
message to GCM
servers.
Google queues
The Android
and stores the
application
message in case
processes the
the device is
message
offline.
On the device,
the system
When the device
broadcasts the
is online, Google
message to the
sends the
specified Android.
message to the
This wakes the
device.
Android
application up.
19. Minimum requirements ( device side )
Android 2.2 +
Android market place should be installed
Emulator with Google APIs
Internet connection
Google account ( device version < 4.0.4 )
.
20. Minimum requirements ( server side )
HTTPS application server that should be
Able to communicate with your client.
Able to fire off HTTP requests to the GCM
server.
Able to handle requests and queue data as
needed. For example, it should be able to
perform exponential back off.
Able to store the user device registration id .
21. Android application
Copy the Add a Wire it up
required broadcast in your
libs receiver activity
Make
Add an
changes
Intent
to the
service
manifest
22. Alternate Infrastructures
• Alternative to GCM is required under
following conditions
Limited connectivity to internet services
Security requirement
Guaranteed delivery
SLAs on delivery
No quota limits
• Downsides
Complicated design
Battery consumption on device is higher.
23. Thank you
In case you have more queries please feel free to contact
Amrit.sanjeev@gmail.com (+91 97407 44557 )
@amsanjeev
25. Add required libs
Install Google Cloud Messaging for
android using SDK manager.
Copy gcm.jar from
YOUR_SDK_ROOT/extras/google/gcm-client/dist to
libs in your project folder
26. Changes to Manifest file
Add <use-sdk … >
Declare & use a custom permission
Add additional permissions
internet
get_accounts
wake_lock
27. Write Intentservice
subclass of
com.google.android.gcm.GCMBaseIntentService
must contain a public constructor,
Generally named my_app_package.GCMIntentService
Override the following functions with appropriate logic
onRegistered
onUnRegistered
onMessage
onError
onRecoverableError
28. Add boardcast receiver
add a broadcast receiver with the custom
permissions and following actions
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
Should be defined in the manifest and not
programmatically
This presentation demonstrates the new capabilities of PowerPoint and it is best viewed in Slide Show. These slides are designed to give you great ideas for the presentations you’ll create in PowerPoint 2011!For more sample templates, click the File menu, and then click New From Template. Under Templates, click Presentations.