View
1.247
Download
3
Category
Tags:
Preview:
Citation preview
2012 Copyright M-STAT SA 2012 Copyright M-STAT SA
Mando Stamelaki M-STAT – Mobile Application Developer
Android Cloud2Device Messaging
| | |
Communicate with your app!
Google Service for pushing messages to Android devices.
Android Cloud to Device Messaging (C2DM) is
– a service that helps developers send data from servers to their applications on Android devices.
The service provides a:
– simple,
– lightweight
mechanism that servers can use to:
– tell mobile applications to contact the server directly,
– fetch updated application or user data.
The C2DM service handles
– all aspects of queuing of messages and
– delivery to the target application running on the target device.
What is Android C2DM Framework?
(AC2DM)
Android Cloud to Device Messaging Framework
Mando Stamelaki | Android Cloud2Device Messaging
Introduction to AC2DM
Push Notifications for Android Phones, Tablets and other devices.
AC2DM
• 3rd party application servers send lightweight messages to their Android applications.
• An application on an Android device doesn’t need to be running to receive messages.
• Uses an existing connection for Google services, with the set up Google account on mobile device.
Android Cloud to device Messaging, provided free by Google Servers
• C2DM makes no guarantees about delivery or the order of messages.
• Does not provide built-in user interface or other handling for message data.
• Requires devices running Android 2.2 or higher that also have the Market application installed.
Advantages Disadvantages
Mando Stamelaki | Android Cloud2Device Messaging
M-STAT Service
• No need to setup a server in order to send notification messages.
• User friendly environment.
• Cross-platform push notifications
(iOS supported, Windows Phone on the way!)
In the role of 3rd party server
• Easy integration in your Application
• Full documentation for developers
• Documented code examples
• Easy customizable to your app needs.
• Application ability to inform M-STAT server when a push message is received
• Library provides a built-in handler for messages
Server-side Mobile Application Encountering C2DM disadvantages
Mando Stamelaki | Android Cloud2Device Messaging
coming soon
Android Application (Device)
Servers (C2DM | Client Login)
Notification Server
request register
registration id
registration id [tags]
key id
registration id message
authorization
send id | error
Push message
requests authorization
authorization
C2DM communication Communication flow between M-STAT (3rd party server) and Google
Mando Stamelaki | Android Cloud2Device Messaging
M-STAT Server HTTP Communication protocol
• A device for push notifications
• Update an existing device
REGISTER
• Registration status and tags if any
CURRENT STATUS
• Remove a device from the list
UNREGISTER
Mando Stamelaki | Android Cloud2Device Messaging
Preferences
Preferences
• Enable / Disable C2DM service • Register/Unregister from Google • Register/Unregister from M-STAT
• Register to specific notification tags • An app can let users receive notifications for specific
things (up to each developer) and not everything
• Retrieve registration status
Mando Stamelaki | Android Cloud2Device Messaging
Software Development Kit for M-STAT Notification Service
• Library • Mobile App • Examples
The SDK contains:
Mando Stamelaki | Android Cloud2Device Messaging
SDK
• Implementing the process to register and
unregister from Google servers.
• Connect to M-STAT’s servers and pass the registration id, and other preferences.
Library
Mando Stamelaki | Android Cloud2Device Messaging
SDK
• Representing the usage of library
• Helping developers to test the service without having to implement their own application.
Mobile Helping App
Mando Stamelaki | Android Cloud2Device Messaging
Let’s CODE!!!
Start with . . . adding the Library to your project
Mando Stamelaki | Android Cloud2Device Messaging
Integrate M-STAT’s library AndroidManifest.xml (1 of 2)
<xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gr.mstat.example"
android:versionCode="1" android:versionName="1.0" >
<!-- Android 2.2 -->
<uses-sdk android:minSdkVersion="8" />
<!-- Permissions -->
<permission android:name="gr.mstat.example.permission.C2D_MESSAGE“
android:protectionLevel="signature" />
<uses-permission
android:name="gr.mstat.example.permission.C2D_MESSAGE" />
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- ... other permissions here ... -->
Mando Stamelaki | Android Cloud2Device Messaging
Integrate M-STAT’s library AndroidManifest.xml (2 of 2)
<application><!-- ... any activities | services | receivers here ... -->
<service android:name="gr.mstat.c2dm.C2DMReceiver" />
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter> <!-- Receive the actual message -->
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="gr.mstat.example" />
</intent-filter>
<intent-filter> <!-- Receive the registration id -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="gr.mstat.example" />
</intent-filter>
</receiver>
</application>
<!-- ... other code here ... -->
</manifest>
Mando Stamelaki | Android Cloud2Device Messaging
Single line initialization // this refers to a Context object
// OPTION 1:
// Starts up the service according to a preference from application preferences
PushNotification.registerAuto(this);
// OPTION 2:
// Manual register or unregister to the service
PushNotification.register(this, true);
PushNotification.register(this, false);
// OPTION 3:
// Registration to specific tag notifications
ArrayList<String> tags = new ArrayList<String>();
tags.add("tag_name_1");
// ... any other tags developer wants
tags.add("tag_name_v");
PushNotification.register(this, tags);
// choose according to your needs!
Still under “deep thought” but will look to something like…
Startup class or any class where you want the notification service being initialized
Mando Stamelaki | Android Cloud2Device Messaging
Calling the library
Customized preferences
Library does the dirty job!
Different ways of initialization
BUT ALL WITH:
As less coding as possible!!!
Any Questions?
Resources
1. Google Projects for Android: C2DM http://code.google.com/android/c2dm/
2. Android Cloud To Device Messaging http://android-developers.blogspot.com/2010/05/android-cloud-to-device-messaging.html
3. Android C2DM Push Notification http://stackoverflow.com/questions/6276342/android-c2dm-push-notification
4. Android C2DM server and client implementation working http://markmelive.com/2011/04/android-c2dm-server-and-client-implementation-working/
5. C2DM Tutorial Send push notifications to your applications with Android C2DM | Cloud To Device Messaging Tutorial
http://www.hightechno.info/2011/08/c2dm-tutorial-send-push-notifications.html
6. Android Cloud to Device Messaging (C2DM) - Tutorial http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
7. Cloud to device messaging http://www.androidkit.com/cloud-to-device-messaging
Resources
Mando Stamelaki | Android Cloud2Device Messaging
THANK YOU Mando Stamelaki Mobile Application Developer m.stamelaki@m-stat.gr
M-STAT | Android Clould2Device Messaging
Recommended