Messaging (GCM) became Firebase Cloud Messaging (FCM). • If you’ve used GCM before FCM will be very familiar to you, it’s very easy to get setup to add push notifications to your app. • Firebase Notifications sit on top of FCM to provide even easier push- setup. • Firebase Notification are part of the “Grow" section of the Firebase suite, and are ideally used for marketing purposes.
: { "body" : "great match!", "title" : "Portugal vs. Denmark" } • Data payloads "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "data" : { "name" : "Mario", "comment" : "great match!” } • You can send Notification and Data payloads in the same message.
you extend and add to your manifest. • It allows you to process a notification when your app is in the foreground (or background if sending Data payloads). • This callback won’t be called if your app is in the background and you send a Notification payload. • How do I know if my app is in the foreground? - Count the number of onStart/onStop calls. - Any number of other ways!
void onTokenRefresh() { // Get updated InstanceID token. String token = FirebaseInstanceId.getInstance().getToken(); // Send this to the back end for use later. } }
Firebase Console. • You can send test Notification + Data payloads from the Firebase Console • You CAN’T send Data only payloads from the Firebase Console. - Use the command line instead, if your app server isn’t ready yet. curl --header "Authorization: key=<insert your server key here>" --header Content-Type:"application/json" https://fcm.googleapis.com/fcm/send -d "{\"data\": {\"title\": \"Push it\",\"message\": \"Push it real good\"}, \"to\":\"<insert device token here>\"}"
the end of the day you’re just sending out push notifications to a list of devices based on the firebase device token, or to devices registered against a topic. • The Firebase Console allows you to choose topic subscribers, or particular users as defined in Firebase Analytics, or an individual device. • Given the marketing idea behind Firebase Notifications, the analytics setup is the one Google is pushing. • As with GCM, you can also choose to send the Firebase registration token to your own backend server if you wish to send push messages programatically. • You can see how many people Firebase thinks will receive the notification in the console. • You can also see how users engaged with the notifications that were sent, received, viewed etc.