Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM...
Transcript of Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM...
![Page 1: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/1.jpg)
Sai Gundumonu
Push Notifications on
Android
Sr. Software Engineer
![Page 2: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/2.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/3.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/4.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/5.jpg)
Push Notifications
How it works
5
source: https://developers.google.com/cloud-messaging/gcm
![Page 6: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/6.jpg)
Push Notifications
How it works (in detail)
6
![Page 7: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/7.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/8.jpg)
Push Notifications
Vendors
8
• Firebase
• Push IO
• SessionM
• Urban Airship
• Vibes (uses Xtify internally)
• Xtify (IBM product)
![Page 9: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/9.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/10.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/11.jpg)
Push Notifications
Setup Google project
11
![Page 12: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/12.jpg)
Push Notifications
Setup Google project
12
![Page 13: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/13.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/14.jpg)
Push Notifications
Setup Urban Airship SDK
14
Sample build.gradle dependencies
![Page 15: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/15.jpg)
Push Notifications
Modify Manifest file
15
Sample manifest.xml
![Page 16: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/16.jpg)
Push Notifications
Modify Manifest file (continue)
16
Sample manifest.xml
![Page 17: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/17.jpg)
Push Notifications
Modify Manifest file (continue)
17
Sample manifest.xml
![Page 18: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/18.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/19.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/20.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/21.jpg)
Push Notifications
App is all ready for receiving push notifications
21
![Page 22: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/22.jpg)
Push Notifications
Urban Airship Dashboard
22
![Page 23: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/23.jpg)
Push Notifications
Urban Airship Dashboard
23
![Page 24: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/24.jpg)
Push Notifications
Urban Airship dashboard
24
![Page 25: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/25.jpg)
Push Notifications
25
source: https://firebase.google.com/docs/cloud-messaging/
Firebase architecture
![Page 26: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/26.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/27.jpg)
Push Notifications
27
Implementation steps for Firebase
Code sample & Demo
![Page 28: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/28.jpg)
Push Notifications
Questions ?
28
![Page 29: Push Notifications on Android - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/29.jpg)
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 - files.meetup.com · Push Notifications Short history 4 • C2DM (Cloud to device messaging) launched in 2010 • C2DM is officially deprecated on](https://reader035.fdocuments.in/reader035/viewer/2022062607/6025dc578621f542a54ca78a/html5/thumbnails/30.jpg)
Push Notifications
30
Thank you!