Android notification details and example code

Android notification instance details

1. Use builder mode to create

2. You must set a smallicon or setticker

3. Setcontenttitle, setcontentinfo, setcontenttext and setWhen can be set

4. You can set setdefaults (flashing screen, sound, vibration) and set flags through notification

5. A notification manager (getsystemservice) needs to be obtained for sending; notify(int id,Notification)

6. Clear manager.cancelall (int ID); If you need to access the following 16 APIs, you need to import the V4 package and use the notificationcompat compatible class.

Custom notification

Use remoteviews to create a layout, and then use setcontent () to set it;

Click events are completed using pendingintent

Here is a case

Mainactivity class

Oneactivity class

activity.main.xml

layout.xml

Finally, remember to register activity

Thank you for reading, hope to help you, thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>