

{"id":76263,"date":"2020-02-24T10:54:45","date_gmt":"2020-02-24T05:24:45","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=76263"},"modified":"2021-08-25T14:05:19","modified_gmt":"2021-08-25T08:35:19","slug":"android-notifications","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/android-notifications\/","title":{"rendered":"Android Notifications &#8211; &#8216;Coz your App is pointless without its implementation"},"content":{"rendered":"<p>Notifications are the messages that are visible to the users outside the app UI. These notifications can be the reminder note, message, update message, or information. These can be directly read by the users in the status bar. So here, we will read and understand Android Notification &amp; its working, and implementation.<\/p>\n<p>In this Android notification article, we will see:<\/p>\n<ul>\n<li>Notification Annotations<\/li>\n<li>Methods to Set Properties<\/li>\n<li>Status Bar and Notification<\/li>\n<li>Android Notifications on Device Example<\/li>\n<li>Types of Android Notifications<\/li>\n<li>NotificationCompat.Builder Class<\/li>\n<li>Implementing Android Notification<\/li>\n<\/ul>\n<p>Let&#8217;s discuss the above in detail.<\/p>\n<h2>Android Notification Annotations<\/h2>\n<p>The notification shows up on the screen in such a way that the user can easily understand from which app it is. The way notification appears on the screen, it tells many things to the user such as:<\/p>\n<ul>\n<li>When the notification has come<\/li>\n<li>What is the context of the message<\/li>\n<li>What is there in the message<\/li>\n<\/ul>\n<p>For a better understanding of Android Notification, consider the following:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/lock-screen-notification-dialogue-box.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76415 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/lock-screen-notification-dialogue-box.jpg\" alt=\"notification in android\" width=\"400\" height=\"130\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/lock-screen-notification-dialogue-box.jpg 400w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/lock-screen-notification-dialogue-box-150x49.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/lock-screen-notification-dialogue-box-300x98.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>1. <strong>Application Icon:<\/strong> It shows the icon of the app and it is set using <strong>setSmallIcon()<\/strong>.<\/p>\n<p><strong>2. Application Name:<\/strong> It shows the name of the app whose notification has come up.<\/p>\n<p><strong>3. Time Stamp:<\/strong> It shows the time when the notification had come. Also, it is provided by the system and can be overridden with <strong>setWhen()<\/strong>. It can be hidden using <strong>setShowWhen(false)<\/strong>.<\/p>\n<p><strong>4. Title:<\/strong> Title is set using <strong>setContentTitle()<\/strong>. It is optional. It is set using <strong>setContentTitle()<\/strong>.<\/p>\n<p><strong>5. Text:<\/strong> Text is the message for the user. It is optional. It is set with <strong>setContentText()<\/strong>.<\/p>\n<h3>Set Android Notification Properties<\/h3>\n<p>The properties of Android Notifications can be set using <strong>NotificationCompat.Builder<\/strong> object. Few of the methods to set properties are mentioned below:<\/p>\n<ul>\n<li><strong>setSmallIcon():<\/strong> This method is to set the icon of the notification.<\/li>\n<li><strong>setContentTitle():<\/strong>\u00a0This method is to set the title of the notification.<\/li>\n<li><strong>setContentText():<\/strong> This is to set the text that you want to show as a text message.<\/li>\n<li><strong>setAutoCancel():<\/strong> This sets the cancelable property of a notification.<\/li>\n<li><strong>setPriority():<\/strong> This sets the priority of the notifications.<\/li>\n<\/ul>\n<p>Now see the following example to know how it happens:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">NotificationCompat.Builder my_builder = new NotificationCompat. Builder(this). setSmallIcon(R.drawable.notification_icon).setContentTitle(\"This is a Sample notification\").setContentText(\"Hi, Welcome to DataFlair.com\");<\/pre>\n<h3>Status Bar and Notification<\/h3>\n<p>The status bar is that part of our screen wherein the android notifications are shown. Notifications can appear on our screen in various forms such as image notification, text notification, expandable notifications, and many more.<\/p>\n<p>Let us see a few of them one by one:<\/p>\n<h4>1. Application Icons<\/h4>\n<p>Application icons of the <a href=\"https:\/\/data-flair.training\/blogs\/android-application-components\/\"><em><strong>application<\/strong><\/em><\/a> from which notification has come are shown on the left of the Status bar.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-interface.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76416 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-interface.jpg\" alt=\"application icon\" width=\"300\" height=\"141\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-interface.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-interface-150x71.jpg 150w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>2. Notifications on the Notification Drawer<\/h4>\n<p>A list of all the android notifications that have come are found in the notification drawer. <strong>For example<\/strong>, consider the following screenshot.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-drawer-in-android.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76417 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-drawer-in-android.jpg\" alt=\"android notification drawer\" width=\"300\" height=\"650\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-drawer-in-android.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-drawer-in-android-69x150.jpg 69w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Notification-drawer-in-android-138x300.jpg 138w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>3. Text Notification<\/h4>\n<p>Following is an example of how the notification is actually shown on the screen.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Text-Notification.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76316 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Text-Notification.png\" alt=\"text notification in android\" width=\"300\" height=\"650\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Text-Notification.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Text-Notification-69x150.png 69w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Text-Notification-138x300.png 138w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>4. Expandable Notification<\/h4>\n<p>These notifications look just like a normal notification, but they can be expanded for further details.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Notification-drawer-youtube-.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76423 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Notification-drawer-youtube-.jpg\" alt=\"android notification drawer\" width=\"400\" height=\"104\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Notification-drawer-youtube-.jpg 400w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Notification-drawer-youtube--150x39.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Notification-drawer-youtube--300x78.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>Let&#8217;s have a look at the expanded notification drawer.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Expanded.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76424 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Expanded.jpg\" alt=\"expanded notification drawer\" width=\"300\" height=\"650\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Expanded.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Expanded-69x150.jpg 69w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Android-Expanded-138x300.jpg 138w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>5. Notification Action<\/h4>\n<p>Another notification is the one where actions can be directly performed in the notification itself. As you can see in the following:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Smart-Reply.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76320 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Smart-Reply.png\" alt=\"android notification action\" width=\"300\" height=\"650\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Smart-Reply.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Smart-Reply-69x150.png 69w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Smart-Reply-138x300.png 138w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h4>6. Lock Screen Notification<\/h4>\n<p>Android Notifications can also be visible on the lock screen. You can see the following for that:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Lock-screen-notification.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76321 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Lock-screen-notification.png\" alt=\"lock screen android notification\" width=\"300\" height=\"650\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Lock-screen-notification.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Lock-screen-notification-69x150.png 69w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/Lock-screen-notification-138x300.png 138w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h3>Types of Android Notifications<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76427 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications.jpg\" alt=\"android notification types\" width=\"778\" height=\"286\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications.jpg 778w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications-150x55.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications-300x110.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications-768x282.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-android-notifications-520x191.jpg 520w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/a><\/h3>\n<p>There are various<a href=\"https:\/\/en.wikipedia.org\/wiki\/Android_version_history\"> types<\/a> of android notifications that we are going to see now.<\/p>\n<h4>1. User-Generated Notifications<\/h4>\n<p>These notifications are generated by users. They are the most common android notifications. Messaging notification is the best example of this. Some other user-generated notification examples are post sharing, liking, commenting, etc.<\/p>\n<h4>2. Context-Generated Notifications<\/h4>\n<p>These are rapidly increasing every day. This type of android notification generates based on the permission to the applications. <strong>For example<\/strong>, schedules, or location-based notifications.<\/p>\n<h4>3. System-Generated Notifications<\/h4>\n<p>These notifications are those that are generated by the apps based on their own needs. <strong>For Example<\/strong>, consider notification of System Updates.<\/p>\n<p><em><strong>Learn to build your first <a href=\"https:\/\/data-flair.training\/blogs\/create-android-app\/\">android app<\/a> with DataFlair.<\/strong><\/em><\/p>\n<h4>4. Push Notifications<\/h4>\n<p>They are the notifications generated by the system. You can consider every notification to be of Push Notification types.<\/p>\n<h4>5. Notifications that Require User\u2019s Action<\/h4>\n<p>These android notifications are those that require users to take immediate action on them. It can be an email alert or it can also be a message.<\/p>\n<h4>6. Passive Notification<\/h4>\n<p>These are the notifications that provide users with some information. There is no need to take any action on it. <strong>For example<\/strong>, a weather update.<\/p>\n<h4>7. Smart Notification<\/h4>\n<p>A smart notification has a unique ability that it delivers to each application.<\/p>\n<h3>Defining Android Notification<\/h3>\n<p>In Android, if we want to use Android Notification we must define it first. We can define some action or some button to the notification too. This will help the users too directly perform the <a href=\"https:\/\/data-flair.training\/blogs\/android-activity\/\"><em><strong>activity<\/strong><\/em><\/a> they wish to perform.<\/p>\n<p>To define it in <strong>MainActivity.java<\/strong>, we will write the code as follow:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this)\r\n\/\/coding part\r\nIntent resultIntent = new Intent(this, MainActivity.class);\r\nPendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);\r\nnBuilder.setContentIntent(pendingIntent);<\/pre>\n<h3>Issuing the Android Notification<\/h3>\n<p>After we are done with the creation of the Notification we are now capable of passing a notification to the system. We can do it using the <strong>NotificationManager.notify()<\/strong> method. We also need to set an id to the Notification so that we can later use it to make changes in the notification.<\/p>\n<p>For this, we will use the following syntax:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">NotificationCompat.Builder nBuilder = new NotificationCompat .Builder(this);\r\n\/\/ coding part\r\nint mNotificationId = 999;\r\nNotificationManager mNotifyMgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);\r\n\/\/ Builds the notification and issues it.\r\nmNotifyMgr.notify(mNotificationId, nBuilder.build());<\/pre>\n<h3>NotificationCompat.Builder Class<\/h3>\n<p>A NotificationCompat.Builder class allows easier control, as well as helps to design different design layouts for notifications. Some of the methods of NotificationCompat.Builder class as given below:<\/p>\n<table class=\"df-table-center\">\n<tbody>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400\">Methods<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><span style=\"font-weight: 400\">build()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It combines all already set options and returns a new notification object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><span style=\"font-weight: 400\">setAutoCancel(boolean autoCancel)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It auto-cancels a notification under given condition.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><span style=\"font-weight: 400\">setContent(RemoteViews views)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets the custom RemoteView to use.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><span style=\"font-weight: 400\">setContentIntent(PendingIntent intent)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets a PendingIntent to work onClick.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><span style=\"font-weight: 400\">ContentInfo(CharSequence info)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets a large text in the right of Notification<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><span style=\"font-weight: 400\">setContentTitle(charSequence title)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets the Title of the notification<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7<\/span><\/td>\n<td><span style=\"font-weight: 400\">setLargeIcon(Bitmap icon)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets the large icon image for the notification<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8<\/span><\/td>\n<td><span style=\"font-weight: 400\">setDefaults(int defaults)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Sets the default notification<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9<\/span><\/td>\n<td><span style=\"font-weight: 400\">setSmallIcon(int icon)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets a small icon for the notification layout.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10<\/span><\/td>\n<td><span style=\"font-weight: 400\">setStyle(NotificationCompat.Style style)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It Adds a rich style to the notification<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11<\/span><\/td>\n<td><span style=\"font-weight: 400\">setVibrate(long[] pattern)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets a pattern of Vibration to vibrate when the notification comes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12<\/span><\/td>\n<td><span style=\"font-weight: 400\">setTicker(charSequence tickerText)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets the text to display when notification comes.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13<\/span><\/td>\n<td><span style=\"font-weight: 400\">setOngoing(boolean ongoing)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It sets in true or false whether the notification is ongoing or not.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>NotificationCompat.Builder class allows easier control over all the flags, as well as help constructing the typical notification layouts.<\/p>\n<h3>Implementing Android Notification in our Application<\/h3>\n<p>Now we will see how we can implement android notification using one example:<\/p>\n<p><strong>Step 1:<\/strong> First of all we will create a New Project and name it. We will write the following code in its <strong>activity_main.xml<\/strong> part:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n   android:layout_width=\"match_parent\"\r\n   android:layout_height=\"match_parent\"\r\n   android:orientation=\"vertical\"&gt;\r\n\r\n   &lt;TextView\r\n       android:id=\"@+id\/textView2\"\r\n       android:layout_width=\"wrap_content\"\r\n       android:layout_height=\"wrap_content\"\r\n       android:layout_centerHorizontal=\"true\"\r\n       android:layout_marginLeft=\"100dp\"\r\n       android:layout_marginTop=\"100dp\"\r\n       android:fontFamily=\"@font\/abril_fatface\"\r\n       android:text=\"DataFlair \"\r\n       android:textColor=\"@color\/colorPrimaryDark\"\r\n       android:textSize=\"50dp\" \/&gt;\r\n\r\n   &lt;Button\r\n       android:id=\"@+id\/btnShow\"\r\n       android:layout_width=\"wrap_content\"\r\n       android:layout_height=\"wrap_content\"\r\n       android:layout_marginLeft=\"100dp\"\r\n       android:layout_marginTop=\"175dp\"\r\n       android:text=\"Generate notification\" \/&gt;\r\n&lt;\/LinearLayout&gt;\r\n\r\n<\/pre>\n<p><strong>Step 2:<\/strong> After this, we will write the code for it\u2019s functioning, in <strong>MainActivity.java<\/strong>. The code is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.DataFlair.dataflairnotification;\r\n\r\nimport androidx.appcompat.app.AppCompatActivity;\r\nimport androidx.core.app.NotificationCompat;\r\nimport android.app.Notification;\r\nimport android.app.NotificationChannel;\r\nimport android.app.NotificationManager;\r\nimport android.content.Context;\r\nimport android.os.Build;\r\nimport android.os.Bundle;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\n\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n   @Override\r\n   protected void onCreate(Bundle savedInstanceState) {\r\n       super.onCreate(savedInstanceState);\r\n       setContentView(R.layout.activity_main);\r\n       Button btnNotify = (Button)findViewById(R.id.btnShow);\r\n       btnNotify.setOnClickListener(new View.OnClickListener() {\r\n           @Override\r\n           public void onClick(View v) {\r\n\r\n               NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\r\n               String NOTIFICATION_CHANNEL_ID = \"my_channel_id_01\"; \/\/ We'll add Notification Channel Id using NotificationManager.\r\n\r\n               if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {\r\n                   NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, \"My Notifications\", NotificationManager.IMPORTANCE_HIGH);\r\n\r\n                   \/\/ Configure the notification channel.\r\n                   notificationChannel.setDescription(\"Channel description\");\r\n                   notificationChannel.enableLights(true);\r\n                   notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});\r\n                   notificationChannel.enableVibration(true);\r\n                        \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notificationManager.createNotificationChannel(notificationChannel);\r\n               }\r\n               NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this, NOTIFICATION_CHANNEL_ID);\r\n\r\n               notificationBuilder.setAutoCancel(true)\r\n                       .setDefaults(Notification.DEFAULT_ALL)\r\n                       .setWhen(System.currentTimeMillis())\r\n                       .setSmallIcon(R.drawable.ic_notification)\r\n                       .setContentTitle(\"DataFlair sent a notification\")\r\n                       .setContentText(\" This is an example of Notification\");\r\n\r\n               notificationManager.notify(\/*notification id*\/1, notificationBuilder.build());\r\n\r\n           }\r\n       });\r\n   }\r\n}<\/pre>\n<p><strong>Step 3:<\/strong> And we will now run our code as follows:<\/p>\n<p><strong>i)<\/strong> The Output would come like this:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/App.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76322 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/App.png\" alt=\"output of android notification\" width=\"300\" height=\"533\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/App.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/App-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/App-169x300.png 169w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>ii)<\/strong> After this, we will click on the <strong>\u201cgenerate notification\u201d<\/strong>.<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76323 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click.png\" alt=\"generate notification\" width=\"300\" height=\"533\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-169x300.png 169w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>iii)<\/strong> You can find the notification in the <strong>Notification Drawer<\/strong> as follows:<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-Notification.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-76324 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-Notification.png\" alt=\"notification drawer in android\" width=\"300\" height=\"533\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-Notification.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-Notification-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/On-Click-Notification-169x300.png 169w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>So, in this Android Notification article, we have seen what are notifications, their types, and their implementation. Other than that we have seen its different types and different appearances on the screen. Not to forget, we have seen the properties of these android notifications and how we can set them.<\/p>\n<p>This was all about DataFlair&#8217;s Android Notification article. I hope you find this article helpful, do share this article on social media to help others.<\/p>\n<p>Happy Learning\ud83d\ude03<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1181,&quot;href&quot;:&quot;https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Android_version_history&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251007224155\\\/https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Android_version_history&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 02:48:53&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2025-12-31 07:12:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-01-03 12:07:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-03 07:03:20&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-25 22:48:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-02 06:41:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 15:10:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-23 05:46:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 22:22:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-22 05:43:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-26 19:13:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-06 16:22:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-05-28 13:50:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-12 19:28:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-21 08:19:23&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-21 08:19:23&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notifications are the messages that are visible to the users outside the app UI. These notifications can be the reminder note, message, update message, or information. These can be directly read by the users&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":76328,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18722],"tags":[21977,21978,21982,21983,21979,21980,21981],"class_list":["post-76263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-android-notification","tag-android-notifications","tag-implementing-android-notification","tag-issuing-the-android-notification","tag-notification-in-android","tag-status-bar-and-notification","tag-types-of-android-notifications"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Notifications - &#039;Coz your App is pointless without its implementation - DataFlair<\/title>\n<meta name=\"description\" content=\"Understand Android Notifications, its working, and how to implement them. As well as, explore status bar and notification, android notification types, etc with us.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/android-notifications\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Notifications - &#039;Coz your App is pointless without its implementation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Understand Android Notifications, its working, and how to implement them. As well as, explore status bar and notification, android notification types, etc with us.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/android-notifications\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-24T05:24:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:35:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Notifications - 'Coz your App is pointless without its implementation - DataFlair","description":"Understand Android Notifications, its working, and how to implement them. As well as, explore status bar and notification, android notification types, etc with us.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/android-notifications\/","og_locale":"en_US","og_type":"article","og_title":"Android Notifications - 'Coz your App is pointless without its implementation - DataFlair","og_description":"Understand Android Notifications, its working, and how to implement them. As well as, explore status bar and notification, android notification types, etc with us.","og_url":"https:\/\/data-flair.training\/blogs\/android-notifications\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-02-24T05:24:45+00:00","article_modified_time":"2021-08-25T08:35:19+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Android Notifications &#8211; &#8216;Coz your App is pointless without its implementation","datePublished":"2020-02-24T05:24:45+00:00","dateModified":"2021-08-25T08:35:19+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/"},"wordCount":1254,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg","keywords":["android notification","android notifications","Implementing Android Notification","Issuing the Android Notification","notification in android","status bar and notification","types of android notifications"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/android-notifications\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/","url":"https:\/\/data-flair.training\/blogs\/android-notifications\/","name":"Android Notifications - 'Coz your App is pointless without its implementation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg","datePublished":"2020-02-24T05:24:45+00:00","dateModified":"2021-08-25T08:35:19+00:00","description":"Understand Android Notifications, its working, and how to implement them. As well as, explore status bar and notification, android notification types, etc with us.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/android-notifications\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/02\/android-notifications.jpg","width":802,"height":420,"caption":"notification in android"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/android-notifications\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Android Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/android\/"},{"@type":"ListItem","position":3,"name":"Android Notifications &#8211; &#8216;Coz your App is pointless without its implementation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/76263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=76263"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/76263\/revisions"}],"predecessor-version":[{"id":76428,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/76263\/revisions\/76428"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/76328"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=76263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=76263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=76263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}