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

Knock Knock! You have a notification

Avatar for Divya Jain Divya Jain
October 26, 2018
180

Knock Knock! You have a notification

Does your phone get bombarded with various notifications throughout day and night? Scared of missing out on important events or updates from your crucial apps? Android notifications have come a long way from being just a simple text to expanded layouts, customization, notification badges and a high level of user control. Most importantly, Notifications are now grouped into channels which allows you to control and customize the kind of notifications you want to receive as a user and provide as a developer.

Through this presentation:

Evolution of different kinds of notifications: Basic notification, Expandables, Heads up Notification, notifications with actions, badges

Notification channel: What, how and management

Notification Importance and their outcome

Quick Demo of how to create notifications from your app

What improvements are further expected with Android P and beyond!

At the end, you will walk away with a deep insight into the world of these everyday knock knocks in your phone's status bar, that notify you of different happenings.

Avatar for Divya Jain

Divya Jain

October 26, 2018
Tweet

Transcript

  1. Val e N t i t o t g e

    b Use ’s at r e n re t in n e s e t a p Vs Not at t i g b i p be or
  2. • Evo on • How r a • Im ov

    t • Bes r ce Wha we k ab ?
  3. “Mes di l to us u s o t A

    p U to v e f at of ki ”
  4. Simple title with one line text Expandable notification templates Actions

    through Buttons User control over notifications per app basis Android Wear Support Notifications for Lock screen & Heads up Grouped notifications Notification channels App badges
  5. val intent = Intent(this, MyApp::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or

    Intent.FLAG_ACTIVITY_CLEAR_TASK } val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, intent, 0) val mBuilder = NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(text_title) .setContentText(text_content) .setContentIntent(pendingIntent) .setAutoCancel(true) Not at I te
  6. val shareIntent= Intent(this, MyShareclass::class.java).apply { Action = ACTION_SHARE putExtra(NOTIFICATION_ID, 0)

    } val sharePendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, shareIntent, 0) val mBuilder = NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(text_title) .setContentText(text_content) .setContentIntent(pendingIntent) .setAutoCancel(true) .addAction(R.drawable.share, getString(R.string.share), sharePendingIntent) Ac i b on
  7. val mBuilder = NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(“multiple emails from..”) .setContentText(text_content)

    .setLargeIcon(myBitmap) .setStyle(NotificationCompat.InboxStyle() .addLine(snippet1) .addLine(snippet2) In o St e t i t o
  8. var message1 = NotificationCompat.MessagingStyle.Message(messages[0].getText(), messages[0].getTime(), messages[0].getSender()) var message2 = NotificationCompat.MessagingStyle.Message(messages[1].getText(),

    messages[1].getTime(), messages[1].getSender()) var notification = NotificationCompat.Builder(mContext, CHANNEL_ID) .setSmallIcon(R.drawable.new_message) .setStyle(NotificationCompat.MessagingStyle(resources.getString(R.string.reply_name)) .addMessage(message1) .addMessage(message2)) Mes n S y e fi on
  9. val user = Person.Builder().setIcon(userIcon).setName(userName).build(); val style = NotificationCompat.MessagingStyle(user) .addMessage(messages[1].getText(), messages[1].getTime(),

    messages[1].getPerson()) .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson()) .setGroupConversation(hasMultiplePeople() .setConversationTitle(“Title”) val noti = NotificationCompat.Builder() .setContentTitle("2 new messages from" + sender.toString()) .setContentText(subject) .setSmallIcon(R.drawable.icon) .setLargeIcon(myBitmap) .setStyle(style) Mes n S y e fi on Foc he ag av !
  10. var notification = NotificationCompat.Builder(context, CHANNEL_ID) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.ic_stat_player) // Add media

    control buttons that invoke intents in your media service .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent) // #0 .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent) // #1 .addAction(R.drawable.ic_next, "Next", nextPendingIntent) // #2 .setStyle(MediaNotificationCompat.MediaStyle() .setShowActionsInCompactView(1) .setMediaSession(mMediaSession.getSessionToken())) .setContentTitle("Music title") .setContentText("Music content") .setLargeIcon(albumArtBitmap) .build() Med le ic o
  11. Gro Not at 7.0+, se r a d if i

    n a Gr Sy em o t a l ro t e h 4 or no ca s, if s if Sy em o t a l l a g su r val GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL" var mBuilder = NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.icon) .setContentTitle(textTitle) .setContentText(textContent) .setLargeIcon(R.drawable.large_icon) .setGroup(GROUP_KEY_WORK_EMAIL)
  12. Bac r m a b i y Man y e

    t a m no ca The y e t y em w val notification1, val notification2, val notification3 val summaryNotification = NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle(emailObject.getSummary()) .setContentText("Three new messages") .setSmallIcon(R.drawable.ic_notify_summary_status) .setStyle(NotificationCompat.InboxStyle() .addLine("line 1") .addLine("line 2") .setBigContentTitle("3 new messages") .setSummaryText("work_email") .setGroup(GROUP_KEY_WORK_EMAIL) .setGroupSummary(true) .build()
  13. Not at C an s Fin in n ol h

    u ve t i t o Notification1 Notification Channel Notification2 User Control
  14. Not at C an s if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

    val name = getString(R.string.channel_name) val descriptionText = getString(R.string.channel_description) val importance = NotificationManager.IMPORTANCE_DEFAULT val mChannel = NotificationChannel(CHANNEL_ID, name, importance) mChannel.description = descriptionText val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager notificationManager.createNotificationChannel(mChannel) }
  15. Not at C an c om i n • en

    Lig s() • se L h or() • en Vib on() • se V r i P t e n() • se S d() • se L k en il () • ca S w e()
  16. He d no ca s Flo g i d r

    a n Im o t wa s o t er, w e d e s oc
  17. Loc re N if i n Lev de s i

    b o t er ec oc c e setVisibility() VISIBILITY_PUBLIC VISIBILITY_SECRET VISIBILITY_PRIVATE
  18. Ap i n ge New fi on c o f

    d e n of p a n r i val mChannel = NotificationChannel(id, name, importance).apply { description = descriptionText setShowBadge(false) } var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID) .setContentTitle("New Messages") .setNumber(messageCount) .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
  19. Do n s u b Tot en : al n

    f i r ti Ala s O y : en s i r ti f al s Pri y O y : us n i r i *Cha l n o r e D mo y se B p n ()
  20. Ke p us ga ! • Use l a t

    s e • Mak m a na • Per li • Pri iz • Avo N if i n li s • Tim • Gro no ca s • Dis c en ca