Notification is used to realize the notification of status bar in Android
When using the mobile phone, when there is a missed call or a new short message, the mobile phone will give a response prompt message, which is usually displayed on the status bar of the mobile phone screen.
Android also provides classes for processing this information, which are notification and notificationmanager. Among them, notification represents the notification with global effect, and notification manager is the system service used to send notification notifications.
Sending and displaying notifications using notification and notificationmanager classes is also relatively simple, which can be roughly divided into the following four steps
(1) Call the getsystemservice () method to get the notificationmanager service of the system
(2) Create a notification object and set various properties for it
(3) Set event information for the notification object
(4) Send notification notifications through the notify () method of the notificationmanager class
The following is an example to illustrate and use notification to display notifications on the status bar
International practice
Operation results:
The layout file does not issue two buttons for linear and vertical layout
MainActivity.class
For the indicator light and vibration set in the above code, since the program needs to access the indicator light and vibrator of the system, the permission should be declared in androidmanifest.xml
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!