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

Rich Android notifications

Rich Android notifications

An overview of ever changing and evolving android notifications, how they behave from Android 6 to Android 10. Best practices, guidelines, anti-patterns and pitfalls to watch out for, while designing and implementing push notification for Android apps.

Himanshu Walia

November 26, 2019
Tweet

More Decks by Himanshu Walia

Other Decks in Technology

Transcript

  1. Topics • Why Use? • Types of notifications • API

    Behaviour changes • Best practices & Pitfalls
  2. Inline replies Android N 7 Notification<— Action <—RemoteInput val remoteInput

    = RemoteInput.Builder(EXTRA_COMMENT) .setLabel(replyLabel) .build() val replyAction: Action = NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, pendingIntent) .addRemoteInput(remoteInput) .setAllowGeneratedReplies(true) .build() notificationCompatBuilder .addAction(replyAction)
  3. Android N 7 Updating your notification val messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(

    notification) // Add new message. messagingStyle.addMessage(replyCharSequence, currentTimeMillis(), null as Person?) // Updates and push Notification // Updates and pushes active Notification val updatedNotification = notificationCompatBuilder // Adds a line and comment below content in Notification .setRemoteInputHistory(arrayOf(comment)) .build()
  4. sender = Person.Builder() .setName("Me MacDonald") .setKey("1234567890") .setUri(“tel:1234567890") .setBot(true) .setIcon(IconCompat.createWithResource(context, R.drawable.me_macdonald))

    .build() NotificationCompat.MessagingStyle(sender) .addMessage("Check this out!", Date().time, sender) .setBuilder(notificationBuilder) Android P 9 val message = Notification.MessagingStyle.Message(message, time, sender) .setData("image/", imageUri) Focus on display
  5. Android 10 API 29 val remoteInput = RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel) //

    List of quick response choices from ML // .setChoices(possiblePostResponses) .build() val replyAction = NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent) .addRemoteInput(remoteInput) .setAllowGeneratedReplies(true) .build() // Adds additional actions specified above. .addAction(replyAction) .setAllowSystemGeneratedContextualActions(true) Smart Replies
  6. Android 10 API 29 <activity android:name=".bubbles.BubbleActivity" android:allowEmbedded="true" android:documentLaunchMode="always" android:resizeableActivity="true" val

    bubbleMetadata = BubbleMetadata.Builder() // The height of the expanded bubble. .setDesiredHeight(this.resources.getDimensionPixelSize(R.dimen.bubble_height)) .setIcon(IconCompat.createWithAdaptiveBitmap(BitmapFactory.decodeResource( resources, R.drawable.wendy_wonda) )) // The Intent to be used for the expanded bubble. .setIntent(bubbleActivityIntent) val builder = Notification.Builder(context, CHANNEL_ID) .setBubbleMetadata(bubbleMetadata) .addPerson(chatBot) Bubbles (preview)
  7. •Segment your users •Take the time of day into account

    •Actionable •Group and Prioritise
  8. •Notification icon (consider dark mode) •Avoid Custom view for notifications

    •large_icon 64dp * 64dp •big_picture 284dp * 416dp Pitfalls