18
AC2DM: Push sobre android Fernando Cejas - @fernando_cejas Fernando García - @fegabe

Android Cloud To Device Messaging

Embed Size (px)

DESCRIPTION

Explanation about push for Android using the Android Cloud to Device Messaging Library.

Citation preview

Page 1: Android Cloud To Device Messaging

AC2DM: Push sobre

android

Fernando Cejas - @fernando_cejasFernando García - @fegabe

Page 2: Android Cloud To Device Messaging

Agenda

Introduction What’s Push? Push vs. Poll Cloud to device messaging Android Implementation Build your app ? F.A.Q

Page 3: Android Cloud To Device Messaging

Introduction

“fastDove Push” App for this demo Who we

are?

http://bit.ly/ac2dm_sample

Page 4: Android Cloud To Device Messaging

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

Page 5: Android Cloud To Device Messaging

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

Page 6: Android Cloud To Device Messaging

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

Page 7: Android Cloud To Device Messaging

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

Page 8: Android Cloud To Device Messaging

AC2DM Lifecycle1. Register device for

Push2. App server send

message

3. Device receives message

4. Unregister device

Page 9: Android Cloud To Device Messaging

Build your app Requesting a Registration ID

C2DMessaging.register(this, "[email protected]");

Page 10: Android Cloud To Device Messaging

Build your app Receiving the Registration ID

public class C2DMReceiver extends C2DMBaseReceiver {

public C2DMReceiver() {super("[email protected]");

}

@Overridepublic void onRegistered(Context context, String registrationId)

{ // TODO send registration ID to the app server

}...

}

Page 11: Android Cloud To Device Messaging

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

}}

Page 12: Android Cloud To Device Messaging

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>

Page 13: Android Cloud To Device Messaging

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 -->

Page 14: Android Cloud To Device Messaging

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 protected] -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

Page 15: Android Cloud To Device Messaging

F.A.Q

Page 16: Android Cloud To Device Messaging

WHO IS THE WINNER????

Page 17: Android Cloud To Device Messaging

Thanks!!!

http://www.fastdove.com/

@fastdove@fastdovedev

[email protected]

Fernando Cejas - @fernando_cejasFernando García - @fegabe

Page 18: Android Cloud To Device Messaging

Say thanks to the people I got information from:

@johanni@vogella