Summary and analysis of Android notification

classification

Notification has the following types:

1 > general notification

1. Content title

2. Large icon

3. Content

4. Content additional information

5. Small icons

6. Time

2 > large layout notification

Figure 1

The large layout notification was added after Android 4.1. The large layout notification is different from the small layout notification only in the '7' part, and other parts are the same. Large layout notification displays a large layout only when the top face of all notifications, and displays a small layout in other cases. You can also expand it into a large layout with your fingers (provided it is a large layout). As shown below:

Figure 2

There are three types of large layout Notifications: as shown in Figure 1, notificationcompat In@R_ 395_ 2419@Style Type. On the left of Figure 2 is notificationcompat.bigtextstyle. On the right of Figure 2 is notificationcompat.bigpicturestyle

3 > custom layout notification

In addition to the notification provided by the system, we can also customize the notification. A music player controls notification as shown in the following figure:

Figure 3

How to create a notification

1 > instantiate a notificationcompat.builder object; Such as builder

2 > call the relevant methods of the builder to set the notification as mentioned above

3 > call the builder. Build () method, which returns a notification object.

4 > instantiate a notificationmanager object; For example: Manager

5 > call the notify method of manager.

Note:

A notification does not need to set all the above options, but three items are required:

Small icon, set by setsmalleicon()

Content title, set by setcontenttitle()

Content, set by setcontenttext()

Sample code

1> Return to the main application interface

Sometimes we may need to implement such a function: when we click notification, a slightly larger window will pop up to display the whole message. The function of this window is to display the whole message content, which has nothing to do with other activities in this application. Then, when we click "back", we will directly return to the mobile phone desktop. To realize such a function, we only need to call the. Setcontentintent method of the builder, and then configure the activity to jump to in the configuration file:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>