Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Messaging

Johann du Toit
September 26, 2016

Cloud Messaging

Talk about features of Cloud Messaging presented at Launch Pad BUILD 2016

Johann du Toit

September 26, 2016
Tweet

More Decks by Johann du Toit

Other Decks in Technology

Transcript

  1. co-Founder/Technical lead at Googl Developer Expert for Johann du Toit

    Hail from johanndutoit.net - @Johann_du_Toit
  2. Famous services not only solve user problems but also do

    great at becoming an integral part of their lives — a habit. Dasha Stremetska https://stfalcon.com/en/blog/post/how-to-build-habit-forming-startups
  3. habit: a settled or regular tendency or practice, especially one

    that is hard to give up. Cambridge Dictionary http://dictionary.cambridge.org/dictionary/english/habit
  4. habit: a settled or regular tendency or practice, especially one

    that is hard to give up. Cambridge Dictionary http://dictionary.cambridge.org/dictionary/english/habit
  5. How do you engage your users to start the first

    step of the hook model ? Someone in the audience
  6. Firebase Cloud Messaging (FCM) is the new version of GCM.

    It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future..
  7. != storage The idea is to pass the message to

    FCM and let the service handle getting it to the user
  8. Token which refers to every registered device, one user could

    have multiple devices Every device is represented by a
  9. notification • Max Size of 2KB • User defined title

    / message • Creates item in system tray • Actionable
  10. data • Max Size of 4KB • Ideal to trigger

    events / sync commands • Invisibly sent to app
  11. normal • Perfect for non-time sensitive apps like Email •

    Does not open network connections on sleeping phones • Conserves battery
  12. high • Perfect for apps that need immediate interaction from

    user - chat / voice alerts etc • Wakes device and opens network connections • Drains a bit more battery
  13. package <package-here>; public class MessageListenService extends FirebaseMessagingService { private static

    final String TAG = "MyFMService"; @Override public void onMessageReceived(RemoteMessage remoteMessage) { // Handle data payload of FCM messages. Log.d(TAG, "FCM Message Id: " + remoteMessage.getMessageId()); Log.d(TAG, "FCM Notification Message: " + remoteMessage.getNotification()); Log.d(TAG, "FCM Data Message: " + remoteMessage.getData()); com.google.firebase.MESSAGING_EVENT
  14. com.google.firebase.INSTANCE_ID_EVENT public class InstanceIDServer extends FirebaseInstanceIdService { private static final

    String TAG = "MyFirebaseIIDService"; @Override public void onTokenRefresh() { // If you need to handle the generation of a token, initially or // after a refresh this is where you should do that. String token = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "FCM Token: " + token);
  15. com.google.firebase.INSTANCE_ID_EVENT public class InstanceIDServer extends FirebaseInstanceIdService { private static final

    String TAG = "MyFirebaseIIDService"; @Override public void onTokenRefresh() { // If you need to handle the generation of a token, initially or // after a refresh this is where you should do that. String token = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "FCM Token: " + token); FirebaseMessaging.getInstance().subscribeToTopic("global");
  16. Firebase Analytical Events FirebaseAnalytics fa = FirebaseAnalytics.getInstance(this); Bundle bundle =

    new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "someid"); bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "somename"); bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image"); fa.logEvent(FirebaseAnalytics.Event.BEGIN_CHECKOUT, bundle);
  17. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } POST https://fcm.googleapis.com/fcm/send
  18. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } POST https://fcm.googleapis.com/fcm/send
  19. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send
  20. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send
  21. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send
  22. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send
  23. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "condition" : " 'TopicA' in topics " } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send
  24. Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "data": { "score": "5x1", "time": "15:10" },

    "condition" : " 'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics) " } https://fcm.googleapis.com/fcm/send POST https://fcm.googleapis.com/fcm/send