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

Christa Mabee: Nougat Notifications

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.

Realm

March 01, 2017
Tweet

More Decks by Realm

Other Decks in Technology

Transcript

  1. 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
  2. ”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)
  3. 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
  4. 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
  5. 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
  6. 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
  7. Using Actions Android uses Intents An Action adds a button

    to the Notification • Launch your app / deeplinks • Calendar data • Web address • Map address • ...
  8. 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);
  9. Keep it timely: updating, stacking, picking the right content •

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

    Personalize it • Make it timely • Group like notifications • Pick the right copy
  11. • 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
  12. 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.
  13. 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
  14. 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
  15. Step One: Wait on broadcast from your NotificationListenerService implementation Step

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

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