Android Notifications in Android Nougat 7.0

Post on 19-Feb-2017

240 views 3 download

transcript

Notifications

Android OS 4.4Android OS 5.2LockScreenNotification

Augmentation of notification

Android OS 1.5 Android OS 1.6 Android OS 2.3 Heads-UpNotification

Types of notification added from android version 4.1

ONE TWO THREE FOUR FIVE

Big text notification contracted & expanded.

NotificationCompat.Builder notification = new NotificationCompat.Builder(TemplateOne.this);notification.setStyle(new Notification.BigTextStyle().bigText("theblogofinfinite replied...")) .build();

notification.setStyle(new Notification.InboxStyle() .addLine("Soandso likes your post") .addLine("Soandso reblogged your post") .setContentTitle("3 new notes") .setSummaryText("+3 more")) .build();

Roll-Up NotificationsBig Picture Notifications

notification.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap)).build();

Action Notifications

NotificationCompat.Action visitBlog = new NotificationCompat.Action(R.drawable.ic_person, "Visit blog", mPendingBlogIntent);NotificationCompat.Action follow = new NotificationCompat.Action(R.drawable.ic_follow, "Follow", mPendingFollowIntent);notification.addAction(visitBlog).addAction(visitBlog).addAction(follow).build();

Custom Notifications

Custom Music player Notification Custom Weather Notification

Android Nougat

Notifications

Direct ReplyWith direct reply feature in Android N, users can quickly respond to text message or update the task directly within the notification interface.

Direct Reply

1. Create an instance of RemoteInput.Builder that you can add to your notification action.

2. Attach the RemoteInput object to an action using addRemoteInput().

// Key for the string that's delivered in the action's intent.private static final String KEY_TEXT_REPLY = "key_text_reply";String replyLabel = getResources().getString(R.string.reply_label);RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)        .setLabel(replyLabel)        .build();

// Create the reply action and add the remote input.Notification.Action action =        new Notification.Action.Builder(R.drawable.ic_reply_icon,                getString(R.string.label), replyPendingIntent)                .addRemoteInput(remoteInput)                .build();

Direct Reply

3. Applying the action to a notification and issue the notification.// Build the notification and add the action.Notification newMessageNotification =        new Notification.Builder(mContext)                .setSmallIcon(R.drawable.ic_message)                .setContentTitle(getString(R.string.title))                .setContentText(getString(R.string.content))                .addAction(action))                .build();

// Issue the notification.NotificationManager notificationManager = NotificationManager.from(mContext);notificationManager.notify(notificationId, newMessageNotification);

Swipe behaviour for notifications. Swiping the notification shows a gear icon behind which can be used to make changes to when a notification for the app should be fired.

Android WearNotifications

Android WearSome of the visual updates and comparision between wear 1.x and wear 2.0

• Android Wear 2.0 updates the visual style of notifications as well as introduces expanded notifications, which provide substantial additional content and actions in an app-like experience.

• Update touch targets of a notification.

• Dark background color.

• Updated horizontal swipe gesture on a notification

Expanded Notification

1. Adding additional content.

• To show additional content in your expanded notification, see Adding Pages to a Notification.

• Additional content pages are stacked vertically in the expanded notification and appear in the order they were added. These additional content pages can optionally use a style such as BigTextStyle or BigPictureStyle.

2. Primary action

• The expanded notification will contain one primary action, which is the first action in the notification unless a different action is specified using setContentAction().

3. Additional actions

• To specify additional actions, use addAction() or addActions(). The action drawer of the expanded notification contains all available actions.

Smart Reply

// Create the reply action and add the remote inputNotificationCompat.Action action =new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,getString(R.string.label), replyPendingIntent).addRemoteInput(remoteInput)

// Allow generated replies.setAllowGeneratedReplies(true).build();

References

• https://www.objc.io/issues/11-android/android-notifications/

• http://www.androidcentral.com/whats-new-android-n

• https://developer.android.com/preview/features/notification-updates.html

• https://www.youtube.com/watch?v=-iog_fmm6mE

Queries ??Thank You Pankaj Lilan

Android Developer @ Gracia Marcom

pankaj.lilan@gmail.com

www.pankajlilan.com

@PankajLilan