Android Cloud To Device Messaging
Post on 10-May-2015
2149 Views
Preview:
DESCRIPTION
Transcript
AC2DM: Push sobre
android
Fernando Cejas - @fernando_cejasFernando García - @fegabe
Agenda
Introduction What’s Push? Push vs. Poll Cloud to device messaging Android Implementation Build your app ? F.A.Q
Introduction
“fastDove Push” App for this demo Who we
are?
http://bit.ly/ac2dm_sample
What is Push?Push technology, or server push, describes a style of Internet-based communication where the request for a given transaction is initiated by the publisher or central server.
Harder to implement Less battery
consumption Constant connection
Push vs Poll…
Any news?
No!Any news?
No!
Any news?
No! New content!
Any news?
Yes! (News)
Push me your news!
News!
poll
push
Transfer content as soon as available
Save device battery Reduce data traffic for user
Cloud to device messaging…
HaIt allows third-party application servers to send lightweight messages to their Android applications
C2DM makes no guarantees about delivery or the order of messages
An application on an Android device doesn’t need to be running to receive messages
Cloud to device messaging…
It does not provide any built-in user interface or other handling for message data
It requires devices running Android 2.2 or higher that also have the Market application installed
It uses an existing connection for Google services
AC2DM Lifecycle1. Register device for
Push2. App server send
message
3. Device receives message
4. Unregister device
Build your app Requesting a Registration ID
C2DMessaging.register(this, "sender@gmail.com");
Build your app Receiving the Registration ID
public class C2DMReceiver extends C2DMBaseReceiver {
public C2DMReceiver() {super("sender@gmail.com");
}
@Overridepublic void onRegistered(Context context, String registrationId)
{ // TODO send registration ID to the app server
}...
}
Build your app Receiving Messages
public class C2DMReceiver extends C2DMBaseReceiver {...
@Overrideprotected void onMessage(Context context, Intent intent) {
String payload = intent.getStringExtra("payload");// TODO handle the message
}}
Build your app Android Manifest
<application> ...
<!-- required for AC2DM --> <service android:name="com.fastdove.sample.ac2dm.C2DMReceiver" />
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.fastdove.sample.ac2dm" /> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.fastdove.sample.ac2dm" /> </intent-filter> </receiver> <!-- END required for AC2DM -->
</application>
Build your app Android Manifest
<application> ...
</application>
<!-- required for AC2DM --> <permission android:name="com.fastdove.notifications.demo.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.fastdove.notifications.demo.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" />
<!-- END required for AC2DM -->
Build your app Request Authorization Token
$ curl https://www.google.com/accounts/ClientLogin -d accountType=GOOGLE -d source=Google-cURL-Example -d service=ac2dm -d Email=sender@gmail.com -d "Passwd=***"
Send Message
$ curl --header "Authorization: GoogleLogin auth=authorization_id" "https://android.apis.google.com/c2dm/send" -d registration_id=device_registration_id -d "data.payload=your message" -d collapse_key=something
F.A.Q
WHO IS THE WINNER????
Thanks!!!
http://www.fastdove.com/
@fastdove@fastdovedev
info@fastdove.com
Fernando Cejas - @fernando_cejasFernando García - @fegabe
Say thanks to the people I got information from:
@johanni@vogella
top related