Site icon C1CTech

Android Notification Example

&NewLine;<p>This post is about android notification&comma; how to create a simple notification&comma; notification styles&comma; how to add actions in notifications with the help of simple android application&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class&equals;"wp-block-embed&lowbar;&lowbar;wrapper">&NewLine;<amp-youtube layout&equals;"responsive" width&equals;"1200" height&equals;"675" data-videoid&equals;"r0do1KgYNDA" title&equals;"Android Notification Example"><a placeholder href&equals;"https&colon;&sol;&sol;youtu&period;be&sol;r0do1KgYNDA"><img src&equals;"https&colon;&sol;&sol;i&period;ytimg&period;com&sol;vi&sol;r0do1KgYNDA&sol;hqdefault&period;jpg" layout&equals;"fill" object-fit&equals;"cover" alt&equals;"Android Notification Example"><&sol;a><&sol;amp-youtube>&NewLine;<&sol;div><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<div class&equals;"wp-block-buttons aligncenter is-layout-flex wp-block-buttons-is-layout-flex">&NewLine;<div class&equals;"wp-block-button"><a class&equals;"wp-block-button&lowbar;&lowbar;link has-white-color has-text-color has-background" href&equals;"https&colon;&sol;&sol;github&period;com&sol;arunk7839&sol;AndroidNotificationExample" style&equals;"background-color&colon;&num;520599" target&equals;"&lowbar;blank" rel&equals;"noreferrer noopener"><strong>DOWNLOAD CODE<&sol;strong><&sol;a><&sol;div>&NewLine;<&sol;div>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;000080&semi;"><strong>Notification<&sol;strong><&sol;span><&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">A Notifications provide short&comma; timely information about events happened in the application&comma; even if the application is not running&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;000080&semi;"><strong>Creating a Basic Notification<&sol;strong><&sol;span><&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">A notification in its most basic and compact form &lpar;or collapsed form&rpar; displays an icon&comma; a title&comma; and a small amount of content text&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;Screen-Shot-2020-08-27-at-4&period;25&period;26-PM&period;png" alt&equals;"Screen Shot 2020-08-27 at 4&period;25&period;26 PM" class&equals;"wp-image-2065"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Setting the notification content<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p>To create a basic notification&comma; we can set the notification content with the following properties &colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>CHANNEL&lowbar;ID<&sol;strong><&sol;span>&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setPriority&lpar;NotificationCompat&period;PRIORITY&lowbar;DEFAULT&rpar;<&sol;strong><&sol;span>&NewLine; &period;build&lpar;&rpar;&semi;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>setSmallIcon&lpar;&rpar;&colon; <&sol;strong><span style&equals;"color&colon; &num;000000&semi;">S<&sol;span><span style&equals;"color&colon; &num;000000&semi;"><i><span style&equals;"color&colon; &num;000000&semi;">et<&sol;span> the <strong><span style&equals;"color&colon; &num;008000&semi;">small icon<&sol;span><&sol;strong> in notification&period; This is the only required property and it&nbsp&semi;appears in the status bar&period;<&sol;i><&sol;span><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;Screen-Shot-2020-08-26-at-9&period;45&period;38-PM&period;png" alt&equals;"Screen Shot 2020-08-26 at 9&period;45&period;38 PM" class&equals;"wp-image-2016"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>setContentTitle&lpar;&rpar;&colon; <&sol;strong><span style&equals;"color&colon; &num;000000&semi;"><i>Set the <strong><span style&equals;"color&colon; &num;008000&semi;">title<&sol;span><&sol;strong> of the notification&period;<&sol;i><&sol;span><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>setContentText&lpar;&rpar;&colon; <&sol;strong><span style&equals;"color&colon; &num;000000&semi;"><i>Set the <strong><span style&equals;"color&colon; &num;008000&semi;">text<&sol;span><&sol;strong> of the notification&period;<&sol;i><&sol;span><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>setPriority&lpar;&rpar;&colon; <&sol;strong><span style&equals;"color&colon; &num;000000&semi;"><i>Set the <strong><span style&equals;"color&colon; &num;008000&semi;">priority<&sol;span><&sol;strong> of notification&period; This property will work only on Android 7&period;1 and lower&period; &lpar;For Android 8&period;0 and higher&comma; you must instead set the channel importance&rpar;<&sol;i><&sol;span><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>Note&colon;<&sol;strong><&sol;span> <span style&equals;"color&colon; &num;008000&semi;"><strong>CHANNEL&lowbar;ID<&sol;strong><&sol;span> is required for Android 8&period;0 &lpar;API level 26&rpar; and higher&comma; but is ignored by older versions&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Creating a notification channel&nbsp&semi;<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">Starting in Android 8&period;0 &lpar;API level 26&rpar; &comma; all notifications must be assigned to a channel or it will not appear&period; One app can have multiple notification channels&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p>By categorising notifications into channels&comma; users can disable specific notification channels for your app &lpar;instead of disabling all your notifications&rpar;&comma; and users can control the visual and auditory options for each channel—all from the Android system settings&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p>On devices running Android 7&period;1 &lpar;API level 25&rpar; and lower&comma; each app only has one channel&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">To create a notification channel&comma; follow these steps&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<ol class&equals;"ol1 wp-block-list"><li class&equals;"li1">Construct a&nbsp&semi;<span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">NotificationChannel<&sol;span><&sol;strong><&sol;span>&nbsp&semi;object with a unique channel ID&comma; a user-visible name&comma; and an importance level&period;<&sol;li><li class&equals;"li1">Optionally&comma; specify the description that the user sees in the system settings with&nbsp&semi;<span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">setDescription&lpar;&rpar;<&sol;span><&sol;strong><&sol;span>&period;<&sol;li><li class&equals;"li1">Register the notification channel by passing it to&nbsp&semi;<strong><span style&equals;"color&colon; &num;008000&semi;"><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;reference&sol;android&sol;app&sol;NotificationManager&num;createNotificationChannel&lpar;android&period;app&period;NotificationChannel&rpar;"><span class&equals;"s1">createNotificationChannel&lpar;&rpar;<&sol;span><&sol;a><&sol;span><&sol;strong>&period; Use <span style&equals;"color&colon; &num;008000&semi;"><strong><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;reference&sol;android&sol;app&sol;NotificationManager&num;createNotificationChannels&lpar;java&period;util&period;List&amp&semi;lt&semi;android&period;app&period;NotificationChannel&amp&semi;gt&semi;&rpar;"><span class&equals;"s1">createNotificationChannels&lpar;&rpar;<&sol;span><&sol;a><&sol;strong><&sol;span>&nbsp&semi; to create multiple notification channels in a single operation&period;<&sol;li><&sol;ol>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted"><strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Unique channel ID<&sol;span><&sol;strong>&NewLine;final String CHANNEL&lowbar;ID &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine;private void createNotificationChannel&lpar;&rpar; &lbrace;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Create the NotificationChannel&comma; but only on API 26&plus; because<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; the NotificationChannel class is new and not in the support library<&sol;span><&sol;strong>&NewLine; if &lpar;Build&period;VERSION&period;SDK&lowbar;INT &gt&semi;&equals; Build&period;VERSION&lowbar;CODES&period;O&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Channel name<&sol;strong><&sol;span>&NewLine; CharSequence name &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;Channel description<&sol;strong><&sol;span>&NewLine; String description &equals; "This channel will show notification only to important people"&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;The importance level you assign to a channel applies to all notifications that you post to it&period;<&sol;span><&sol;strong>&NewLine; int importance &equals; NotificationManager&period;IMPORTANCE&lowbar;DEFAULT&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Create the NotificationChannel<&sol;span><&sol;strong>&NewLine; NotificationChannel channel &equals; new NotificationChannel&lpar;CHANNEL&lowbar;ID&comma; name&comma; importance&rpar;&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Set channel description<&sol;strong><&sol;span>&NewLine; channel&period;setDescription&lpar;description&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Register the channel with the system&semi; you can't change the importance<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; or other notification behaviors after this<&sol;span><&sol;strong>&NewLine; NotificationManager notificationManager &equals; getSystemService&lpar;NotificationManager&period;class&rpar;&semi;&NewLine; notificationManager&period;createNotificationChannel&lpar;channel&rpar;&semi;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p>Notification settings for <strong>NotificationTest<&sol;strong> app and one of its channel <strong>&lpar;Important&lowbar;mail&lowbar;channel&rpar;&period;<&sol;strong><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"wp-block-heading"><img class&equals;"alignnone wp-image-2026" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;Screenshot&lowbar;1598511682&period;png" alt&equals;"Screenshot&lowbar;1598511682" width&equals;"323" height&equals;"574">&nbsp&semi; &nbsp&semi; &nbsp&semi; <img class&equals;"alignnone wp-image-2028" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;Screenshot&lowbar;1598511690&period;png" alt&equals;"Screenshot&lowbar;1598511690" width&equals;"324" height&equals;"575"><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"wp-block-heading">&nbsp&semi;<&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Setting the notification&&num;8217&semi;s tap action<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">To perform some operation on notification&&num;8217&semi;s tap&comma; you must specify a content intent defined with a <span style&equals;"color&colon; &num;008000&semi;"><strong><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;reference&sol;android&sol;app&sol;PendingIntent"><span class&equals;"s1">PendingIntent<&sol;span><&sol;a><&sol;strong><&sol;span>&nbsp&semi;object and pass it to&nbsp&semi;<strong><span style&equals;"color&colon; &num;008000&semi;"><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;reference&sol;androidx&sol;core&sol;app&sol;NotificationCompat&period;Builder&num;setContentIntent&lpar;android&period;app&period;PendingIntent&rpar;"><span class&equals;"s1">setContentIntent&lpar;&rpar;<&sol;span><&sol;a>&period;<&sol;span><&sol;strong><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">The following snippet shows how to create a basic intent to open an url when the user taps the notification&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted"><span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;open the url when user taps the notification<&sol;strong><&sol;span>&NewLine;Intent <strong>intent<&sol;strong> &equals; new Intent&lpar;Intent&period;ACTION&lowbar;VIEW&comma; Uri&period;parse&lpar;"https&colon;&sol;&sol;www&period;c1ctech&period;com&sol;"&rpar;&rpar;&semi;&NewLine;PendingIntent <strong>pendingIntent<&sol;strong> &equals; PendingIntent&period;<strong>getActivity<&sol;strong>&lpar;this&comma; 0&comma; <strong>intent<&sol;strong>&comma; 0&rpar;&semi;&NewLine;&NewLine;Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setPriority&lpar;NotificationCompat&period;PRIORITY&lowbar;DEFAULT&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Set the intent that will fire when the user taps the notification<&sol;span><&sol;strong>&NewLine; <strong>&period;setContentIntent&lpar;pendingIntent&rpar;<&sol;strong>&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;removes the notification when the user taps it<&sol;strong><&sol;span>&NewLine; &period;setAutoCancel&lpar;true&rpar;&NewLine; &period;build&lpar;&rpar;&semi;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Show the notification<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">To make the notification appear&comma; call&nbsp&semi;<strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;">NotificationManagerCompat&period;notify&lpar;&rpar;<&sol;span><&sol;strong>&comma; passing it a <span style&equals;"color&colon; &num;008000&semi;"><strong>unique ID<&sol;strong><&sol;span> for the notification and the <strong><span style&equals;"color&colon; &num;008000&semi;">Notification <&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">object<&sol;span>&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">NotificationManagerCompat mNotificationManagerCompat&semi;&NewLine;&NewLine;Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setLargeIcon&lpar;bitmap&rpar;&NewLine; &period;setPriority&lpar;NotificationCompat&period;PRIORITY&lowbar;DEFAULT&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Set the intent that will fire when the user taps the notification<&sol;span><&sol;strong>&NewLine; &period;setContentIntent&lpar;pendingIntent&rpar;&NewLine; &period;setAutoCancel&lpar;true&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;notificationId must be unique int for each notification<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;000000&semi;"><strong>mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;<&sol;strong><&sol;span><&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;000080&semi;"><strong>Android Notification Styles<&sol;strong><&sol;span><&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">By default&comma; the notification&&num;8217&semi;s text content is truncated to fit one line&period; If you want your notification to be longer&comma; you can enable an expandable notification by adding a style template with&nbsp&semi;<span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;"><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;reference&sol;androidx&sol;core&sol;app&sol;NotificationCompat&period;Builder&num;setStyle&lpar;android&period;support&period;v4&period;app&period;NotificationCompat&period;Style&rpar;">setStyle&lpar;&rpar;<&sol;a>&period;<&sol;span><&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>BigText Style<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p class&equals;"p1">This style should be used when a notification contains a large block of text&period; It lets the user preview more text when the notification is expanded&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">final String <span style&equals;"color&colon; &num;0000ff&semi;"><strong>CHANNEL&lowbar;ID<&sol;strong><&sol;span> &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine;private void createBigTextNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; Bitmap <strong>bitmap<&sol;strong> &equals; BitmapFactory&period;decodeResource&lpar;getResources&lpar;&rpar;&comma;&NewLine; R&period;drawable&period;nature&lowbar;img&rpar;&semi;&NewLine;&NewLine; NotificationCompat&period;BigTextStyle <strong>style<&sol;strong> &equals; new NotificationCompat&period;BigTextStyle&lpar;&rpar;&period;<span style&equals;"color&colon; &num;008000&semi;"><strong>bigText<&sol;strong><&sol;span>&lpar;text &plus; " used for generating large-format notifications that include a lot of text&period;"&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set different title in expanded mode&period;<&sol;strong> <&sol;span>&NewLine; <strong>&period;setBigContentTitle&lpar;null&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;needed if an app sends notification from multiple sources&lpar;accounts&rpar;&period;<&sol;span>&NewLine; &period;setSummaryText&lpar;"BigTextStyle"&rpar;&semi;<&sol;strong>&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; <strong><span style&equals;"color&colon; &num;0000ff&semi;">CHANNEL&lowbar;ID<&sol;span><&sol;strong>&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text &plus; " used for generating large-format notifications that include a lot of text&period;"&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set BigTextStyle<&sol;strong><&sol;span>&NewLine; <strong><span style&equals;"color&colon; &num;0000ff&semi;">&period;setStyle&lpar;style&rpar;<&sol;span>&NewLine;<&sol;strong> <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set the large icon in the notification&period;<&sol;strong><&sol;span>&NewLine; &period;setLargeIcon&lpar;<strong>bitmap<&sol;strong>&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Collapsed Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;BigTextStyleNotification&period;png" alt&equals;"BigTextStyleNotification" class&equals;"wp-image-1991"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Expanded Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;BigTextStyleNotificationExpandable&period;png" alt&equals;"BigTextStyleNotificationExpandable" class&equals;"wp-image-1992"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>BigPicture Style<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p>This style should be used when a notification contains a picture&period; The large icon offers a thumbnail of the picture&comma; and the user can get a bigger preview by expanding the notification&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">final String <span style&equals;"color&colon; &num;0000ff&semi;"><strong>CHANNEL&lowbar;ID<&sol;strong><&sol;span> &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine;private void createBigPictureNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; Bitmap <strong>bitmap<&sol;strong> &equals; BitmapFactory&period;decodeResource&lpar;getResources&lpar;&rpar;&comma;&NewLine; R&period;drawable&period;nature&lowbar;img&rpar;&semi;&NewLine;&NewLine; NotificationCompat&period;BigPictureStyle <strong>style<&sol;strong> &equals; new NotificationCompat&period;BigPictureStyle&lpar;&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;set big picture<&sol;strong><&sol;span>&NewLine; &period;bigPicture&lpar;bitmap&rpar;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"> <strong style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set the content text in expanded form&period;<&sol;strong><&sol;span>&NewLine; &period;setSummaryText&lpar;"BigPicture style is used to show large image&period;"&rpar;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;set different title in expanded mode&period;<&sol;strong><&sol;span>&NewLine; &period;setBigContentTitle&lpar;null&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set different large icon in expanded mode&period;<&sol;strong><&sol;span>&NewLine; &period;bigLargeIcon&lpar;null&rpar;&semi;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; <strong><span style&equals;"color&colon; &num;0000ff&semi;">CHANNEL&lowbar;ID<&sol;span><&sol;strong>&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setLargeIcon&lpar;<strong>bitmap<&sol;strong>&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set Big picture template<&sol;strong><&sol;span>&NewLine; <strong><span style&equals;"color&colon; &num;0000ff&semi;">&period;setStyle&lpar;style&rpar;<&sol;span><&sol;strong>&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Collapsed Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;BigPictureStyleNotification&period;png" alt&equals;"BigPictureStyleNotification" class&equals;"wp-image-1993"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Expanded Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;BigPictureStyleNotificationExpandable&period;png" alt&equals;"BigPictureStyleNotificationExpandable" class&equals;"wp-image-1994"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<h4 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Inbox Style<&sol;strong><&sol;span><&sol;h4>&NewLine;&NewLine;&NewLine;&NewLine;<p>This style should be used when a notification contains a list of strings&period; It lets the user preview more text &lpar;list of strings&rpar; when the notification is expanded&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">final String <span style&equals;"color&colon; &num;0000ff&semi;"><strong>CHANNEL&lowbar;ID<&sol;strong><&sol;span> &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine;private void createInboxNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; String line1 &equals; "This is line1 "&semi;&NewLine; String line2 &equals; "This is line2 "&semi;&NewLine; String line3 &equals; "This is line3 "&semi;&NewLine; String line4 &equals; "This is line4 "&semi;&NewLine; String line5 &equals; "This is line5 "&semi;&NewLine; String line6 &equals; "This is line6 "&semi;&NewLine; String line7 &equals; "This is line7 "&semi;&NewLine;&NewLine; NotificationCompat&period;InboxStyle style &equals; new NotificationCompat&period;InboxStyle&lpar;&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;To add n lines&comma; call it n times<&sol;strong><&sol;span>&NewLine; &period;addLine&lpar;line1&rpar;&NewLine; &period;addLine&lpar;line2&rpar;&NewLine; &period;addLine&lpar;line3&rpar;&NewLine; &period;addLine&lpar;line4&rpar;&NewLine; &period;addLine&lpar;line5&rpar;&NewLine; &period;addLine&lpar;line6&rpar;&NewLine; &period;addLine&lpar;line7&rpar;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;needed if an app send notification from multiple sources&lpar;accounts&rpar;&period;<&sol;span><&sol;strong>&NewLine; &period;setSummaryText&lpar;"InboxStyle"&rpar;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;set different title in expanded form&period;<&sol;strong><&sol;span>&NewLine; &period;setBigContentTitle&lpar;null&rpar;&semi;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; <strong><span style&equals;"color&colon; &num;0000ff&semi;">CHANNEL&lowbar;ID<&sol;span><&sol;strong>&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;"It is used for notifications includes a list of &lpar;up to 5&rpar; strings&period;"&rpar;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;set inbox style in notification<&sol;span><&sol;strong>&NewLine; &period;setStyle&lpar;style&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Collapsed Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;InboxNotification-1&period;png" alt&equals;"InboxNotification" class&equals;"wp-image-1997"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Expanded Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;InboxNotificationExpandable&period;png" alt&equals;"InboxNotificationExpandable" class&equals;"wp-image-1998"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"p1 wp-block-heading"><span style&equals;"color&colon; &num;000080&semi;"><strong>Add Action Buttons<&sol;strong><&sol;span><&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<p>A notification can offer up to three action buttons that allow the user to respond quickly&comma; such as dismiss a notification or even reply to a text message&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p>The following code shows how to send a broadcast to a specific receiver &lpar;cancels the notification of specific notificationId&rpar; on click of action buttons <strong>Dismiss<&sol;strong> and <strong>Delete<&sol;strong>&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">final String CHANNEL&lowbar;ID &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine;private void createActionNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; Intent <strong>intent<&sol;strong> &equals; new Intent&lpar;getApplicationContext&lpar;&rpar;&comma; Receiver&period;class&rpar;&semi;&NewLine; intent&period;setAction&lpar;"ACTION&lowbar;CANCEL"&rpar;&semi;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;passing notificationId to receiver class through intent<&sol;span><&sol;strong>&NewLine; intent&period;putExtra&lpar;"id"&comma; notificationId&rpar;&semi;&NewLine;&NewLine; PendingIntent pendingIntent &equals; PendingIntent&period;getBroadcast&lpar;getApplicationContext&lpar;&rpar;&comma; 0&comma; <span style&equals;"color&colon; &num;000000&semi;"><strong>intent<&sol;strong><&sol;span>&comma; PendingIntent&period;FLAG&lowbar;UPDATE&lowbar;CURRENT&rpar;&semi;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;Action fire on click of notification Dismiss action button<&sol;strong><&sol;span>&NewLine; NotificationCompat&period;Action <strong>actionDismiss<&sol;strong> &equals;&NewLine; new NotificationCompat&period;Action&period;Builder&lpar;0&comma;&NewLine; "Dismiss"&comma; pendingIntent&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;Action fire on click of notification Delete action button<&sol;strong><&sol;span>&NewLine; NotificationCompat&period;Action <strong>actionDelete<&sol;strong> &equals;&NewLine; new NotificationCompat&period;Action&period;Builder&lpar;0&comma;&NewLine; "Delete"&comma; pendingIntent&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setStyle&lpar;new NotificationCompat&period;BigTextStyle&lpar;&rpar;&period;bigText&lpar;"This is an example of BigTextStyle notification with action&period;"&rpar;&rpar;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;Add actions Dismiss and Delete to this notification&period;<&sol;strong><&sol;span>&NewLine; <strong>&period;addAction&lpar;actionDismiss&rpar;&NewLine; &period;addAction&lpar;actionDelete&rpar;<&sol;strong>&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p>A BigTextStyle notification with two action buttons&period;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Collapsed Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;ActionNotification&period;png" alt&equals;"ActionNotification" class&equals;"wp-image-2000"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Expanded Mode&colon;<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<figure class&equals;"wp-block-image"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;ActionNotificationExpandable&period;png" alt&equals;"ActionNotificationExpandable" class&equals;"wp-image-2001"&sol;><&sol;figure>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"wp-block-heading">&nbsp&semi;<&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<h3 class&equals;"wp-block-heading"><span style&equals;"color&colon; &num;000080&semi;"><strong>Creating New Project<&sol;strong><&sol;span><&sol;h3>&NewLine;&NewLine;&NewLine;&NewLine;<p><strong>1<&sol;strong>&period; Create a new project <span style&equals;"color&colon; &num;0000ff&semi;"><strong>NotificationTest<&sol;strong><&sol;span> in <span style&equals;"color&colon; &num;008000&semi;"><strong>Android Studio<&sol;strong><&sol;span>&nbsp&semi;from&nbsp&semi;<span style&equals;"color&colon; &num;008000&semi;"><strong>File &Implies; New Project<&sol;strong>&comma;<&sol;span> fill the project details and then click on <span style&equals;"color&colon; &num;008000&semi;"><strong>finish<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><strong>2<&sol;strong>&period; Open <strong><span style&equals;"color&colon; &num;008000&semi;">activity&lowbar;main&period;xml<&sol;span><&sol;strong> file and add the following code as shown below&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>activity&lowbar;main&period;xml<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;androidx&period;constraintlayout&period;widget&period;ConstraintLayout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MainActivity"&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;btn&lowbar;simple&lowbar;notification"&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;padding&equals;"15dp"&NewLine; android&colon;text&equals;"&commat;string&sol;simple&lowbar;notification&lowbar;title"&NewLine; android&colon;textAllCaps&equals;"false"&NewLine; android&colon;textSize&equals;"18sp"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toTopOf&equals;"&commat;&plus;id&sol;btn&lowbar;bigtextstyle&lowbar;notification"&NewLine; app&colon;layout&lowbar;constraintEnd&lowbar;toEndOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintHorizontal&lowbar;bias&equals;"0&period;5"&NewLine; app&colon;layout&lowbar;constraintStart&lowbar;toStartOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toTopOf&equals;"parent" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;btn&lowbar;bigtextstyle&lowbar;notification"&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;padding&equals;"15dp"&NewLine; android&colon;text&equals;"&commat;string&sol;bigtext&lowbar;notification&lowbar;style&lowbar;title"&NewLine; android&colon;textAllCaps&equals;"false"&NewLine; android&colon;textSize&equals;"18sp"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toTopOf&equals;"&commat;&plus;id&sol;btn&lowbar;bigpicturestyle&lowbar;notification"&NewLine; app&colon;layout&lowbar;constraintEnd&lowbar;toEndOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintHorizontal&lowbar;bias&equals;"0&period;5"&NewLine; app&colon;layout&lowbar;constraintStart&lowbar;toStartOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toBottomOf&equals;"&commat;&plus;id&sol;btn&lowbar;simple&lowbar;notification" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;btn&lowbar;bigpicturestyle&lowbar;notification"&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;padding&equals;"15dp"&NewLine; android&colon;text&equals;"&commat;string&sol;bigPicture&lowbar;notification&lowbar;style&lowbar;title"&NewLine; android&colon;textAllCaps&equals;"false"&NewLine; android&colon;textSize&equals;"18sp"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toTopOf&equals;"&commat;&plus;id&sol;btn&lowbar;inboxstyle&lowbar;notification"&NewLine; app&colon;layout&lowbar;constraintEnd&lowbar;toEndOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintHorizontal&lowbar;bias&equals;"0&period;5"&NewLine; app&colon;layout&lowbar;constraintStart&lowbar;toStartOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toBottomOf&equals;"&commat;&plus;id&sol;btn&lowbar;bigtextstyle&lowbar;notification" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;btn&lowbar;inboxstyle&lowbar;notification"&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;padding&equals;"15dp"&NewLine; android&colon;text&equals;"&commat;string&sol;inbox&lowbar;notification&lowbar;style&lowbar;title"&NewLine; android&colon;textAllCaps&equals;"false"&NewLine; android&colon;textSize&equals;"18sp"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toTopOf&equals;"&commat;&plus;id&sol;btn&lowbar;action&lowbar;notification"&NewLine; app&colon;layout&lowbar;constraintEnd&lowbar;toEndOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintHorizontal&lowbar;bias&equals;"0&period;5"&NewLine; app&colon;layout&lowbar;constraintStart&lowbar;toStartOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toBottomOf&equals;"&commat;&plus;id&sol;btn&lowbar;bigpicturestyle&lowbar;notification" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;btn&lowbar;action&lowbar;notification"&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;padding&equals;"15dp"&NewLine; android&colon;text&equals;"&commat;string&sol;action&lowbar;notification&lowbar;title"&NewLine; android&colon;textAllCaps&equals;"false"&NewLine; android&colon;textSize&equals;"18sp"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toBottomOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintEnd&lowbar;toEndOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintHorizontal&lowbar;bias&equals;"0&period;5"&NewLine; app&colon;layout&lowbar;constraintStart&lowbar;toStartOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toBottomOf&equals;"&commat;&plus;id&sol;btn&lowbar;inboxstyle&lowbar;notification" &sol;&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;androidx&period;constraintlayout&period;widget&period;ConstraintLayout&gt&semi;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p>The layout of the above <span style&equals;"color&colon; &num;008000&semi;"><strong>activity&lowbar;main&period;xml<&sol;strong><&sol;span> file will look like this&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<div class&equals;"wp-block-image"><figure class&equals;"aligncenter is-resized"><img src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;08&sol;Screenshot&lowbar;1598358882&period;png" alt&equals;"Screenshot&lowbar;1598358882" class&equals;"wp-image-2005" width&equals;"395" height&equals;"702"&sol;><&sol;figure><&sol;div>&NewLine;&NewLine;&NewLine;&NewLine;<p><strong>3<&sol;strong>&period; Create a new class <span style&equals;"color&colon; &num;008000&semi;"><strong>Receiver&period;java<&sol;strong><&sol;span> inside project package folder&period; Receiver class <strong><span style&equals;"color&colon; &num;008000&semi;">onReceive&lpar;&rpar;<&sol;span><&sol;strong> will call on click of notification action buttons &lpar;Delete and Dismiss&rpar;&period;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Receiver&period;java<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">package com&period;example&period;notificationtest&semi;&NewLine;&NewLine;import android&period;content&period;BroadcastReceiver&semi;&NewLine;import android&period;content&period;Context&semi;&NewLine;import android&period;content&period;Intent&semi;&NewLine;&NewLine;import androidx&period;core&period;app&period;NotificationManagerCompat&semi;&NewLine;&NewLine;public class Receiver extends BroadcastReceiver &lbrace;&NewLine;&NewLine; &commat;Override&NewLine; public void onReceive&lpar;Context context&comma; Intent intent&rpar; &lbrace;&NewLine;&NewLine; if &lpar;intent &excl;&equals; null&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;get notificationId of notification using intent<&sol;strong><&sol;span>&NewLine; int id &equals; intent&period;getIntExtra&lpar;"id"&comma; 0&rpar;&semi;&NewLine; NotificationManagerCompat notificationManagerCompat &equals; NotificationManagerCompat&period;from&lpar;context&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;cancel the specific notificationId notification&period;<&sol;span><&sol;strong>&NewLine; notificationManagerCompat&period;cancel&lpar;id&rpar;&semi;&NewLine; &rcub;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p><strong>4<&sol;strong>&period; To register the user defined broadcast receiver &lpar;Receiver&period;java&rpar; inside <strong><span style&equals;"color&colon; &num;008000&semi;">AndroidManifest&period;xml <&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">file write the below code&colon;<&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>AndroidManifest&period;xml<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;manifest xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; package&equals;"com&period;example&period;notificationtest"&gt&semi;&NewLine;&NewLine; &lt&semi;application&NewLine; android&colon;allowBackup&equals;"true"&NewLine; android&colon;icon&equals;"&commat;mipmap&sol;ic&lowbar;launcher"&NewLine; android&colon;label&equals;"&commat;string&sol;app&lowbar;name"&NewLine; android&colon;roundIcon&equals;"&commat;mipmap&sol;ic&lowbar;launcher&lowbar;round"&NewLine; android&colon;supportsRtl&equals;"true"&NewLine; android&colon;theme&equals;"&commat;style&sol;AppTheme"&gt&semi;&NewLine;&NewLine; &lt&semi;activity android&colon;name&equals;"&period;MainActivity"&gt&semi;&NewLine; &lt&semi;intent-filter&gt&semi;&NewLine; &lt&semi;action android&colon;name&equals;"android&period;intent&period;action&period;MAIN" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;category android&colon;name&equals;"android&period;intent&period;category&period;LAUNCHER" &sol;&gt&semi;&NewLine; &lt&semi;&sol;intent-filter&gt&semi;&NewLine; &lt&semi;&sol;activity&gt&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&lt&semi;receiver android&colon;name&equals;"&period;Receiver"&gt&semi;<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &lt&semi;intent-filter&gt&semi;<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &lt&semi;category android&colon;name&equals;"android&period;intent&period;categeory&period;DEFAULT"&sol;&gt&semi;<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &lt&semi;&sol;intent-filter&gt&semi;<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> &lt&semi;&sol;receiver&gt&semi;<&sol;strong><&sol;span>&NewLine; &lt&semi;&sol;application&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;manifest&gt&semi;<&sol;pre>&NewLine;&NewLine;&NewLine;&NewLine;<p><strong>5<&sol;strong>&period; Open <strong><span style&equals;"color&colon; &num;008000&semi;">MainActivity&period;java<&sol;span><&sol;strong> and add the below code&colon;<&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>MainActivity&period;java<&sol;strong><&sol;span><&sol;p>&NewLine;&NewLine;&NewLine;&NewLine;<pre class&equals;"wp-block-preformatted">package com&period;example&period;notificationtest&semi;&NewLine;&NewLine;import android&period;app&period;Notification&semi;&NewLine;import android&period;app&period;NotificationChannel&semi;&NewLine;import android&period;app&period;NotificationManager&semi;&NewLine;import android&period;app&period;PendingIntent&semi;&NewLine;import android&period;content&period;Intent&semi;&NewLine;import android&period;graphics&period;Bitmap&semi;&NewLine;import android&period;graphics&period;BitmapFactory&semi;&NewLine;import android&period;net&period;Uri&semi;&NewLine;import android&period;os&period;Build&semi;&NewLine;import android&period;os&period;Bundle&semi;&NewLine;import android&period;view&period;View&semi;&NewLine;import android&period;widget&period;Button&semi;&NewLine;&NewLine;import androidx&period;appcompat&period;app&period;AppCompatActivity&semi;&NewLine;import androidx&period;core&period;app&period;NotificationCompat&semi;&NewLine;import androidx&period;core&period;app&period;NotificationManagerCompat&semi;&NewLine;&NewLine;public class MainActivity extends AppCompatActivity implements View&period;OnClickListener &lbrace;&NewLine;&NewLine; final String CHANNEL&lowbar;ID &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine; Button mBtnSimpleNotification&comma; mBtnBigTextNotification&comma; mBtnBigPictureNotification&comma; mBtnInboxNotification&comma; mBtnActionNotification&semi;&NewLine; NotificationManagerCompat mNotificationManagerCompat&semi;&NewLine;&NewLine; &commat;Override&NewLine; protected void onCreate&lpar;Bundle savedInstanceState&rpar; &lbrace;&NewLine; super&period;onCreate&lpar;savedInstanceState&rpar;&semi;&NewLine; setContentView&lpar;R&period;layout&period;activity&lowbar;main&rpar;&semi;&NewLine;&NewLine; createNotificationChannel&lpar;&rpar;&semi;&NewLine; mBtnSimpleNotification &equals; findViewById&lpar;R&period;id&period;btn&lowbar;simple&lowbar;notification&rpar;&semi;&NewLine; mBtnBigTextNotification &equals; findViewById&lpar;R&period;id&period;btn&lowbar;bigtextstyle&lowbar;notification&rpar;&semi;&NewLine; mBtnBigPictureNotification &equals; findViewById&lpar;R&period;id&period;btn&lowbar;bigpicturestyle&lowbar;notification&rpar;&semi;&NewLine; mBtnInboxNotification &equals; findViewById&lpar;R&period;id&period;btn&lowbar;inboxstyle&lowbar;notification&rpar;&semi;&NewLine; mBtnActionNotification &equals; findViewById&lpar;R&period;id&period;btn&lowbar;action&lowbar;notification&rpar;&semi;&NewLine; mBtnSimpleNotification&period;setOnClickListener&lpar;this&rpar;&semi;&NewLine; mBtnBigTextNotification&period;setOnClickListener&lpar;this&rpar;&semi;&NewLine; mBtnBigPictureNotification&period;setOnClickListener&lpar;this&rpar;&semi;&NewLine; mBtnInboxNotification&period;setOnClickListener&lpar;this&rpar;&semi;&NewLine; mBtnActionNotification&period;setOnClickListener&lpar;this&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat &equals; NotificationManagerCompat&period;from&lpar;MainActivity&period;this&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&NewLine; &commat;Override&NewLine; public void onClick&lpar;View view&rpar; &lbrace;&NewLine; int viewId &equals; view&period;getId&lpar;&rpar;&semi;&NewLine; switch &lpar;viewId&rpar; &lbrace;&NewLine; case &lpar;R&period;id&period;btn&lowbar;simple&lowbar;notification&rpar;&colon;&NewLine; createSimpleNotification&lpar;getString&lpar;R&period;string&period;simple&lowbar;notification&lowbar;title&rpar;&comma; getString&lpar;R&period;string&period;simple&lowbar;notification&lowbar;text&rpar;&comma; 1&rpar;&semi;&NewLine; break&semi;&NewLine;&NewLine; case &lpar;R&period;id&period;btn&lowbar;bigtextstyle&lowbar;notification&rpar;&colon;&NewLine; createBigTextNotification&lpar;getString&lpar;R&period;string&period;bigtext&lowbar;notification&lowbar;title&rpar;&comma; getString&lpar;R&period;string&period;bigtext&lowbar;notification&lowbar;text&rpar;&comma; 2&rpar;&semi;&NewLine; break&semi;&NewLine;&NewLine; case &lpar;R&period;id&period;btn&lowbar;bigpicturestyle&lowbar;notification&rpar;&colon;&NewLine; createBigPictureNotification&lpar;getString&lpar;R&period;string&period;bigPicture&lowbar;notification&lowbar;title&rpar;&comma; getString&lpar;R&period;string&period;bigPicture&lowbar;notification&lowbar;text&rpar;&comma; 3&rpar;&semi;&NewLine; break&semi;&NewLine;&NewLine; case &lpar;R&period;id&period;btn&lowbar;inboxstyle&lowbar;notification&rpar;&colon;&NewLine; createInboxNotification&lpar;getString&lpar;R&period;string&period;inbox&lowbar;notification&lowbar;title&rpar;&comma; getString&lpar;R&period;string&period;inbox&lowbar;notification&lowbar;text&rpar;&comma; 4&rpar;&semi;&NewLine; break&semi;&NewLine;&NewLine; case &lpar;R&period;id&period;btn&lowbar;action&lowbar;notification&rpar;&colon;&NewLine; createActionNotification&lpar;getString&lpar;R&period;string&period;action&lowbar;notification&lowbar;title&rpar;&comma; getString&lpar;R&period;string&period;action&lowbar;notification&lowbar;text&rpar;&comma; 5&rpar;&semi;&NewLine; break&semi;&NewLine;&NewLine; &rcub;&NewLine; &rcub;&NewLine;&NewLine; private void createSimpleNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;removes all previously shown notifications&period;<&sol;strong><&sol;span>&NewLine; mNotificationManagerCompat&period;cancelAll&lpar;&rpar;&semi;&NewLine;&NewLine; Bitmap bitmap &equals; BitmapFactory&period;decodeResource&lpar;getResources&lpar;&rpar;&comma;&NewLine; R&period;drawable&period;nature&lowbar;img&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;open the url when user taps the notification<&sol;span><&sol;strong>&NewLine; Intent intent &equals; new Intent&lpar;Intent&period;ACTION&lowbar;VIEW&comma; Uri&period;parse&lpar;"https&colon;&sol;&sol;www&period;c1ctech&period;com&sol;"&rpar;&rpar;&semi;&NewLine; PendingIntent pendingIntent &equals; PendingIntent&period;getActivity&lpar;this&comma; 0&comma; intent&comma; 0&rpar;&semi;&NewLine;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setPriority&lpar;NotificationCompat&period;PRIORITY&lowbar;DEFAULT&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Set the intent that will fire when the user taps the notification<&sol;span><&sol;strong>&NewLine; &period;setContentIntent&lpar;pendingIntent&rpar;&NewLine; &period;setAutoCancel&lpar;true&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; notificationId is a unique int for each notification that you must define<&sol;span><&sol;strong>&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&NewLine;&NewLine; private void createBigTextNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;removes all previously shown notifications&period;<&sol;strong><&sol;span>&NewLine; mNotificationManagerCompat&period;cancelAll&lpar;&rpar;&semi;&NewLine;&NewLine; Bitmap bitmap &equals; BitmapFactory&period;decodeResource&lpar;getResources&lpar;&rpar;&comma;&NewLine; R&period;drawable&period;nature&lowbar;img&rpar;&semi;&NewLine;&NewLine; NotificationCompat&period;BigTextStyle style &equals; new NotificationCompat&period;BigTextStyle&lpar;&rpar;&period;bigText&lpar;text &plus; " used for generating large-format notifications that include a lot of text&period;"&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set different title in expanded mode&period;<&sol;strong><&sol;span>&NewLine; &period;setBigContentTitle&lpar;null&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;needed if an app sends notification from multiple sources&lpar;accounts&rpar;&period;<&sol;span><&sol;strong>&NewLine; &period;setSummaryText&lpar;"BigTextStyle"&rpar;&semi;&NewLine;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text &plus; " used for generating large-format notifications that include a lot of text&period;"&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;set Big text template<&sol;span><&sol;strong>&NewLine; &period;setStyle&lpar;style&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;Set the large icon in the notification&period;<&sol;span><&sol;strong>&NewLine; &period;setLargeIcon&lpar;bitmap&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine;&NewLine; private void createBigPictureNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;removes all previously shown notifications&period;<&sol;strong><&sol;span>&NewLine; mNotificationManagerCompat&period;cancelAll&lpar;&rpar;&semi;&NewLine;&NewLine;&NewLine; Bitmap bitmap &equals; BitmapFactory&period;decodeResource&lpar;getResources&lpar;&rpar;&comma;&NewLine; R&period;drawable&period;nature&lowbar;img&rpar;&semi;&NewLine;&NewLine;&NewLine; NotificationCompat&period;BigPictureStyle style &equals; new NotificationCompat&period;BigPictureStyle&lpar;&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set big picture<&sol;span><&sol;strong>&NewLine; &period;bigPicture&lpar;bitmap&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set the content text in expanded form&period;<&sol;span><&sol;strong>&NewLine; &period;setSummaryText&lpar;"BigPicture style is used to show large image&period;"&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set different title in expanded mode&period;<&sol;span><&sol;strong>&NewLine; &period;setBigContentTitle&lpar;null&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set different large icon in expanded mode&period;<&sol;span><&sol;strong>&NewLine; &period;bigLargeIcon&lpar;null&rpar;&semi;&NewLine;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Set the large icon in the notification&period;<&sol;span><&sol;strong>&NewLine; &period;setLargeIcon&lpar;bitmap&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;set Big picture template<&sol;strong><&sol;span>&NewLine; &period;setStyle&lpar;style&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine;&NewLine; &rcub;&NewLine;&NewLine; private void createInboxNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;removes all previously shown notifications&period;<&sol;strong><&sol;span>&NewLine; mNotificationManagerCompat&period;cancelAll&lpar;&rpar;&semi;&NewLine;&NewLine; String line1 &equals; "This is line1 "&semi;&NewLine; String line2 &equals; "This is line2 "&semi;&NewLine; String line3 &equals; "This is line3 "&semi;&NewLine; String line4 &equals; "This is line4 "&semi;&NewLine; String line5 &equals; "This is line5 "&semi;&NewLine; String line6 &equals; "This is line6 "&semi;&NewLine; String line7 &equals; "This is line7 "&semi;&NewLine;&NewLine; NotificationCompat&period;InboxStyle style &equals; new NotificationCompat&period;InboxStyle&lpar;&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;To add n lines&comma; call it n times<&sol;span><&sol;strong>&NewLine; &period;addLine&lpar;line1&rpar;&NewLine; &period;addLine&lpar;line2&rpar;&NewLine; &period;addLine&lpar;line3&rpar;&NewLine; &period;addLine&lpar;line4&rpar;&NewLine; &period;addLine&lpar;line5&rpar;&NewLine; &period;addLine&lpar;line6&rpar;&NewLine; &period;addLine&lpar;line7&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;needed if an app sends notification from multiple sources&lpar;accounts&rpar;&period;<&sol;span><&sol;strong>&NewLine; &period;setSummaryText&lpar;"InboxStyle"&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set different title in expanded mode&period;<&sol;span><&sol;strong>&NewLine; &period;setBigContentTitle&lpar;null&rpar;&semi;&NewLine;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;"It is used for notifications includes a list of &lpar;up to 5&rpar; strings&period;"&rpar;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;set inbox style in notification<&sol;span><&sol;strong>&NewLine; &period;setStyle&lpar;style&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine; private void createActionNotification&lpar;String title&comma; String text&comma; int notificationId&rpar; &lbrace;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;removes all previously shown notifications&period;<&sol;span><&sol;strong>&NewLine; mNotificationManagerCompat&period;cancelAll&lpar;&rpar;&semi;&NewLine;&NewLine;&NewLine; Intent intent &equals; new Intent&lpar;getApplicationContext&lpar;&rpar;&comma; Receiver&period;class&rpar;&semi;&NewLine; intent&period;setAction&lpar;"ACTION&lowbar;CANCEL"&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;passing notificationId to receiver class through intent<&sol;span><&sol;strong>&NewLine; intent&period;putExtra&lpar;"id"&comma; notificationId&rpar;&semi;&NewLine;&NewLine; PendingIntent pendingIntent &equals; PendingIntent&period;getBroadcast&lpar;getApplicationContext&lpar;&rpar;&comma; 0&comma; intent&comma; PendingIntent&period;FLAG&lowbar;UPDATE&lowbar;CURRENT&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;action fire on click of notification Dismiss action button&period;<&sol;span><&sol;strong>&NewLine; NotificationCompat&period;Action actionDismiss &equals;&NewLine; new NotificationCompat&period;Action&period;Builder&lpar;0&comma;&NewLine; "Dismiss"&comma; pendingIntent&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;action fire on click of notification Delete action button&period;<&sol;span><&sol;strong>&NewLine; NotificationCompat&period;Action actionDelete &equals;&NewLine; new NotificationCompat&period;Action&period;Builder&lpar;0&comma;&NewLine; "Delete"&comma; pendingIntent&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine;&NewLine; Notification notification &equals; new NotificationCompat&period;Builder&lpar;this&comma; CHANNEL&lowbar;ID&rpar;&NewLine; &period;setSmallIcon&lpar;R&period;mipmap&period;ic&lowbar;launcher&lowbar;round&rpar;&NewLine; &period;setContentTitle&lpar;title&rpar;&NewLine; &period;setContentText&lpar;text&rpar;&NewLine; &period;setStyle&lpar;new NotificationCompat&period;BigTextStyle&lpar;&rpar;&period;bigText&lpar;"This is an example of BigTextStyle notification with action&period;"&rpar;&rpar;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &sol;&sol;Add actions Dismiss and Delete to this notification&period;<&sol;strong><&sol;span>&NewLine; &period;addAction&lpar;actionDismiss&rpar;&NewLine; &period;addAction&lpar;actionDelete&rpar;&NewLine; &period;build&lpar;&rpar;&semi;&NewLine;&NewLine; mNotificationManagerCompat&period;notify&lpar;notificationId&comma; notification&rpar;&semi;&NewLine; &rcub;&NewLine;&NewLine; private void createNotificationChannel&lpar;&rpar; &lbrace;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Create the NotificationChannel&comma; but only on API 26&plus; because<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; the NotificationChannel class is new and not in the support library<&sol;span><&sol;strong>&NewLine; if &lpar;Build&period;VERSION&period;SDK&lowbar;INT &gt&semi;&equals; Build&period;VERSION&lowbar;CODES&period;O&rpar; &lbrace;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol;Channel name<&sol;span><&sol;strong>&NewLine; CharSequence name &equals; "Important&lowbar;mail&lowbar;channel"&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Channel description<&sol;span><&sol;strong>&NewLine; String description &equals; "This channel will show notification only to important people"&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;The importance level you assign to a channel applies to all notifications that you post to it&period;<&sol;span><&sol;strong>&NewLine; int importance &equals; NotificationManager&period;IMPORTANCE&lowbar;DEFAULT&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;Create the NotificationChannel<&sol;strong><&sol;span>&NewLine; NotificationChannel channel &equals; new NotificationChannel&lpar;CHANNEL&lowbar;ID&comma; name&comma; importance&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Set channel description<&sol;span><&sol;strong>&NewLine; channel&period;setDescription&lpar;description&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Register the channel with the system&semi; you can't change the importance<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &sol;&sol; or other notification behaviors after this<&sol;span><&sol;strong>&NewLine; NotificationManager notificationManager &equals; getSystemService&lpar;NotificationManager&period;class&rpar;&semi;&NewLine; notificationManager&period;createNotificationChannel&lpar;channel&rpar;&semi;&NewLine; &rcub;&NewLine; &rcub;&NewLine;&rcub;<&sol;pre>&NewLine;&NewLine;

Exit mobile version