Android NotificationAndroid Notification provides short, timely information about the action happened in the application, even it is not running. The notification displays the icon, title and some amount of the content text. Set Android Notification PropertiesThe properties of Android notification are set using NotificationCompat.Builder object. Some of the notification properties are mention below:
Android Notification ExampleIn this example, we will create a notification message which will launch another activity after clicking on it. activity_main.xmlAdd the following code in an activity_main.xml file. Create an activity named as activity_notification_view.xml and add the following code. This activity will be launched on clicking the notification. TextView is used to display the notification message. activity_notification_view.xmlMainActivity.javaIn the MainActivity.java class adds the following code. In this class, clicking the button calls the addNotification() method where we implement the NotificationCompat.Builder object to set the notification properties. The NotificationManager.notify() method is used to display the notification. The Intent class is used to call another activity (NotificationView.java) on taping the notification. NotificationView.javaThe NotificationView.java class receives the notification message and is displayed in TextView. This class is invoked while taping the notification. strings.xmlAndroidManifest.xmlAdd the following code in AndroidManifest.xml file. Output: Next TopicUsing Google reCAPTCHA |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India