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

Christa Mabee: Nougat Notifications

1fa9cb8c7997c8c4d3d251fb5e41f749?s=47 Realm
March 01, 2017

Christa Mabee: Nougat Notifications

Video: https://www.youtube.com/watch?v=nyqlYKxTOJ8

Speaker: A mobile developer since 2010, Christa has worked on apps, SDKs, and the Android platform for a manufacturer. When not working on, thinking about, or dreaming about programming, she enjoys reading about dead languages and running up steep hills. Her graduate degree is in Computational Linguistics, and her favorite thing from computer science is the kernel trick.

Abstract: What makes a Notification fun? This session will cover novel new methods to trigger Notifications using the Awareness API, actions you can build to engage users immediately, and ideas for ways to make the Notification experience more interesting.
Android 7.0 Nougat provides a range of delightful possibilities. We’ll hit those highlights as we review a case study on Trulia’s foray into using the Awareness API.

1fa9cb8c7997c8c4d3d251fb5e41f749?s=128

Realm

March 01, 2017
Tweet

Transcript

  1. Nougat Notifications Mobile + Web DevCon: Track B – Android

    March 2nd 2017 Christa Mabee
  2. Coming up: • Get started: triggering notifications in time and

    space • Using Actions: how to make the notification functional • Keep it timely: updating, stacking, picking the right content • Don’t break things: testing your Notifications
  3. ”notification” some UI interaction meant to get a user’s attention

    “Notification” a notification that appears in the slider “Push Notification” an alert sent to the application from a service running elsewhere (some backend service, usually via Google Play Services)
  4. None
  5. Examples of most of these concepts are available here: https://github.com/Turnsole/MobileWebDevCon_Notifications

  6. Get started: triggering notifications in time and space Location GeofenceAPI

    (via Google Play Services) Google Beacons (manages beacons that support the Eddystone Bluetooth Profile) Time AlarmManager (local system service) Server-Side Push Notifications via Google Play Services (Might be using Google Cloud Messaging, Urban Airship, Firebase … etc. on the backend) signals
  7. Signal Example Time Current local time Location Latitude and longitude

    Place Place, including place type Activity Detected user activity (walking, running, biking) Beacons Nearby beacons matching the specified namespace Headphones Are headphones plugged in? Weather Current weather conditions The Awareness API ties all these signals together into one API. Get started: triggering notifications in time and space
  8. See developers.google.com/awareness for tutorials. // Fences for time, location, place,

    activity, beacons, headphones, or weather. AwarenessFence walkingFence = DetectedActivityFence.during(DetectedActivityFence.WALKING); AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN); // Any combination of AND, OR, and NOT AwarenessFence fence = AwarenessFence.and(walkingFence, headphoneFence); Intent pending = ... // What happens when the fence is triggered. String tag = ... // Identifier with which to update/remove the fence. request = FenceUpdateRequest.Builder().addFence(tag, fence, pending).build(); Awareness.FenceApi.updateFences(googleApiClient, request); Get started: triggering notifications in time and space
  9. See developers.google.com/awareness for tutorials. Fence API – register fences to

    broadcast an Intent when the fence is “crossed” (conditions are all true) Snapshot API – get the state of any of the signals at a given time Get started: triggering notifications in time and space
  10. Get started: triggering notifications in time and space

  11. Using Actions Android uses Intents An Action adds a button

    to the Notification
  12. Using Actions Android uses Intents An Action adds a button

    to the Notification • Launch your app / deeplinks • Calendar data • Web address • Map address • ...
  13. Using Actions Android uses Intents An Action adds a button

    to the Notification action = new Notification.Action.Builder(icon, “DO THE THING”, pending).build(); Notification.Builder builder = new Notification.Builder(context); builder.addAction(action);
  14. Using Actions

  15. Using Actions

  16. Keep it timely: updating, stacking, picking the right content •

    Personalize it • Make it timely • Group like notifications • Pick the right copy
  17. Keep it timely: updating, stacking, picking the right content •

    Personalize it • Make it timely • Group like notifications • Pick the right copy
  18. Keep it timely: updating, stacking, picking the right content

  19. • Personalize it • Make it timely • Group like

    notifications • Pick the right copy • Give them something to do (Actions) Keep it timely: updating, stacking, picking the right content
  20. Keep it timely: updating, stacking, picking the right content •

    Personalize it • Make it timely • Group like notifications • Pick the right copy • Give them something to do* (Actions) * Using RemoteInput, the user can respond right in the Notification.
  21. NotificationCompat.Builder builder = ... RemoteInput remoteInput = new RemoteInput.Builder(INTENT_EXTRAS_KEY) .setLabel("Hint

    Text Goes Here") .build(); NotificationCompat.Action compatAction = new NotificationCompat.Action.Builder(R.drawable.ic_notification, actionName, pendingIntent) .addRemoteInput(remoteInput) .build(); builder.addAction(compatAction); Keep it timely: updating, stacking, picking the right content
  22. Keep it timely: updating, stacking, picking the right content

  23. Keep it timely: updating, stacking, picking the right content Don’t

    spam.
  24. Testing Notifications This is actually possible. Not kidding.

  25. Testing Notifications Extend NotificationListenerService: @Override public void onNotificationPosted(StatusBarNotification notification) {

    Intent addedIntent = new Intent(ACTION_ADDED); addedIntent.putExtra(NOTIFICATION_EXTRA, notification); getApplication().sendBroadcast(addedIntent); } From your UI test (Espresso etc.), wait on that ACTION_ADDED broadcast. Use UiAutomator to interact with the Notification slider
  26. None
  27. Step One: Wait on broadcast from your NotificationListenerService implementation Step

    Two: Use UIAutomator to open the Notification Step Three: Verify app behavior
  28. • Notification triggers, including the Awareness API • Adding Actions,

    grouping Notifications, picking content • RemoteInput • Testing
  29. ?

  30. The End. Christa Mabee / Trulia / @chrozophora