push notifications on android - meetupfiles.meetup.com/1791179/android_pushnotifications.pdf ·...

30
Sai Gundumonu Push Notifications on Android Sr. Software Engineer

Upload: others

Post on 23-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Sai Gundumonu

Push Notifications on

Android

Sr. Software Engineer

Page 2: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Agenda

2

• What is Push Notification

• Short history

• How it works

• Types of Push Notifications & Venders

• How to implement a push notification using Urban Airship & Firebase

Page 3: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

What is Push Notification

3

Push notifications let your application notify a user of new messages or events even when the user is not actively using your application.

Page 4: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Short history

4

• C2DM (Cloud to device messaging) launched in 2010

• C2DM is officially deprecated on June 26th 2012 and shutdown on Oct 20,2015

• “GCM” Google cloud messaging replaced C2DM

• Battery efficiency & rich set of new APIs.

• GCM’s latest version is “FCM” Firebase cloud messaging.

• Simple client development & out of box notification solution.

Page 5: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

How it works

5

source: https://developers.google.com/cloud-messaging/gcm

Page 6: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

How it works (in detail)

6

Page 7: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Types of Push Notifications

7

• Location based notifications

• Time based notifications

• General notifications

• In-app notification

• In-app message

Page 8: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Vendors

8

• Firebase

• Push IO

• SessionM

• Urban Airship

• Vibes (uses Xtify internally)

• Xtify (IBM product)

Page 9: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Implementation steps(For UA)

9

• Setup Google project

• Setup Urban Airship SDK

• Configure project Manifest file

• Configure Urban airship properties

• Enable Push notifications for the app.

Page 10: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Setup Google project

10

• Create a project in Google Developers Console at https://console.developers.google.com

• Turn GCM for android ON.

• Generate an API Key

• Create new Key in API & auth

• Select server key and click create without entering any IP

Page 11: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Setup Google project

11

Page 12: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Setup Google project

12

Page 13: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Setup Urban Airship SDK

13

• Open your android studio project

• Add compile project (‘:urbanairship-lib-x.x.x’) to dependencies in build.gradle

• Cardview library, google play service GCM and Location (ver 7.0 or newer) are other dependencies.

• Don’t forget to sync the project after updating build.gradle

Page 14: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Setup Urban Airship SDK

14

Sample build.gradle dependencies

Page 15: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Modify Manifest file

15

Sample manifest.xml

Page 16: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Modify Manifest file (continue)

16

Sample manifest.xml

Page 17: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Modify Manifest file (continue)

17

Sample manifest.xml

Page 18: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Configure airshipconfig.properties

18

Create a new airshipconfig.properties file and place it in your project’s assets folder.

Page 19: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Starting Urban Airship Service

19

In your Application object’s onCreate()

Above code will bootstrap the SDK and look for the settings in airshipconfig.properties

This can also optionally be provided at run time by passing an AirshipConfigOptions in the call to com.urbanairship.UAirship#takeOff(Application, AirshipConfigOptions):

Page 20: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Enabling user notification

20

After user’s consent enable notification for your app

The Channel ID is a unique identifier that ties together an application/device pair on Android devices. The Channel ID is used to target pushes to specific devices using the Urban Airship API. Once a Channel ID is created, it will persist the application until it is either reinstalled, or its internal data is cleared.

Page 21: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

App is all ready for receiving push notifications

21

Page 22: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Urban Airship Dashboard

22

Page 23: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Urban Airship Dashboard

23

Page 24: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Urban Airship dashboard

24

Page 25: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

25

source: https://firebase.google.com/docs/cloud-messaging/

Firebase architecture

Page 26: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

26

Implementation steps for Firebase

• Setup Firebase and FCM SDK

• Optional for extra feature.

• A service that extends FirebaseMessagingService

• A service that extends FirebaseInstanceIdService

minSdkVersion 8

Page 27: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

27

Implementation steps for Firebase

Code sample & Demo

Page 28: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

Questions ?

28

Page 29: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

References

29

• http://docs.urbanairship.com/platform/android.html

• https://developers.google.com/android/guides/setup

• https://developers.google.com/cloud-messaging/gcm

• http://docs.urbanairship.com/user-guide/getting-started.html#ug-sending-your-first-push

• https://firebase.google.com

• https://developers.google.com/cloud-messaging/faq

Page 30: Push Notifications on Android - Meetupfiles.meetup.com/1791179/Android_PushNotifications.pdf · 2016-11-11 · Push Notifications Short history 4 • C2DM (Cloud to device messaging)

Push Notifications

30

Thank you!