Slide 1

Slide 1 text

Effective Android Messaging Juan Gomez

Slide 2

Slide 2 text

Agenda • Intro • HTTP • WebSockets • SMS (Text Messages) • Network Service Discovery • Review • Q&A !2

Slide 3

Slide 3 text

Over 2 million events
 140 million tickets sold 
 $2 billion in gross ticket sales
 Events in 179 countries Eventbrite by the Numbers

Slide 4

Slide 4 text

Intro Who am I? • Mobile Engineer at Eventbrite • Android Developer • Python enthusiast !4

Slide 5

Slide 5 text

Intro Slides: • http://lanyrd.com/profile/juandg/ • http://www.andevcon.com/slides !5

Slide 6

Slide 6 text

Intro What do you mean by messaging? • Communications between devices • Peer-to-Peer • Servers are “devices”, and peers too ;) !6

Slide 7

Slide 7 text

Intro Where do I need messaging: • IM apps • Multiplayer games • Enterprise apps • Many more… !7

Slide 8

Slide 8 text

HTTP

Slide 9

Slide 9 text

HTTP • Effective Android HTTP by Jesse Wilson • Presented at AnDevCon Boston • http://bit.ly/1auYlY2 !9

Slide 10

Slide 10 text

HTTP (Native) HttpURLConnection vs Apache HTTP client • Apache HTTP client works better on Eclair (2.1) and Froyo (2.2) • HttpURLConnection is the best choice for Gingerbread (2.3) and above !10

Slide 11

Slide 11 text

HTTP (3rd-party) Volley: • Great performance and memory mgmt • Poor documentation and support OkHttp • Improved fork of HttpURLConnection (as of 4.0) • Great documentation and support !11

Slide 12

Slide 12 text

HTTP • It’s not full duplex • It’s not meant for device peer-to-peer communication • Not ideal for low connectivity scenarios (concerts, arenas, etc.) !12

Slide 13

Slide 13 text

GOOGLE CLOUD MESSAGING !13

Slide 14

Slide 14 text

Google Cloud Messaging !14

Slide 15

Slide 15 text

Google Cloud Messaging • Full duplex • Fire & Forget • Not always reliable • No guarantee on time of delivery • Relatively easy to implement !15

Slide 16

Slide 16 text

Google Cloud Messaging Two implementations: • GCM HTTP • Based on HTTP Post requests • Uses JSON messages • GCM CCS • Based on the XMPP chat protocol • Uses XML messages !16

Slide 17

Slide 17 text

Google Cloud Messaging Android Studio can implement a simple GCM back- end for you, using Google AppEngine • Follow instructions on: • http://googlecloudplatform.blogspot.com/ 2013/06/tutorial-adding-cloud-backend-to-your- application-with-android-studio_26.html !17

Slide 18

Slide 18 text

WEB SOCKETS

Slide 19

Slide 19 text

WebSockets • Full-duplex communication using Port 80 • Web Server <—> Client • Not just for Web Browsers • Near Real-Time !19

Slide 20

Slide 20 text

WebSockets on Android • No native Android implementation !20

Slide 21

Slide 21 text

Web Sockets (3rd Party) AutobahnAndroid • Fully open source • github.com/tavendo/AutobahnAndroid • Commercially supported also Socket.IO client for Android • Fully open source • github.com/koush/android-websockets • Not very well supported !21

Slide 22

Slide 22 text

SMS (TEXT MESSAGING)

Slide 23

Slide 23 text

SMS (Text Messaging) Pros: • Asynchronous • Ideal for low data connectivity • Only option when there’s no data connectivity • Mostly free (in the U.S. and Europe) • Supported by “dumb” phones !23

Slide 24

Slide 24 text

SMS (Text Messaging) Cons: • Asynchronous • No guarantee of delivery (including order) • Limited to 160 characters per message • Android API’s are “mostly” undocumented • Except for the new KitKat API ! !24

Slide 25

Slide 25 text

SMS (Text Messaging) When to use them: • IM apps (duh!) • Device activation • Phone number verification • As a fallback method for other protocol • As a coordination mechanism !25

Slide 26

Slide 26 text

SMS (Text Messaging) SmsManager • Sending is really easy SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(“555-123-456“, null, "hello", null, null); ! ! !26

Slide 27

Slide 27 text

SMS (Text Messaging) Receiving SMS • It’s an undocumented API • Implement a BroadCast receiver listening for: • android.provider.Telephony.SMS_RECEIVED • Bundle contains an array of SmsMessage • Checkout the new KitKat API: • youtu.be/mdq0R2WQssQ !27

Slide 28

Slide 28 text

NETWORK SERVICE DISCOVERY

Slide 29

Slide 29 text

Network Service Discovery • Discover services available on the local network • Based on Apple’s Bonjour • Multiplatform support • Android, iOS, OS X, Linux, Windows, Printers, etc. • Only available on API Level 16 and above !29

Slide 30

Slide 30 text

Network Service Discovery Alternatives if you’re not on API Level 16 yet: • Use JmDNS ( jmdns.sourceforge.net) • Centralized “check-in” Server on fixed IP • DON’T Try to do multicast/broadcast yourself • Not very efficient (really slooow!) • Battery Drain ! ! !30

Slide 31

Slide 31 text

Network Service Discovery Eventbrite engineering blog: • engineering.eventbrite.com • Android NDS Post: http://bit.ly/1aYc6RN !31

Slide 32

Slide 32 text

HOW WE USE IT AT EVENTBRITE? !32

Slide 33

Slide 33 text

How we use this at Eventbrite? Entry Manager • Paired with a home grown solution called “Gatekeeper” !33

Slide 34

Slide 34 text

How we use this at Eventbrite? Eventbrite App • Social Notifications Push notification when two of your friends are attending the same event . ! !34

Slide 35

Slide 35 text

We’re hiring! If you’re interested, let’s talk after the session eventbrite.com/jobs

Slide 36

Slide 36 text

Questions? Download our apps: eventbrite.com/eventbriteapp

Slide 37

Slide 37 text

Thank You! @_juandg [email protected]