Background Knowledge: You can use Activity and Service to start Message notification. The difference between the two is that one is triggered at the foreground, and the other is triggered by the background Service.
To use Message Notification, you must use two classes: icationicationmanager and Notification. For initialization of other NotificationManager, The getSystemService method is used, and the y method is used to send message bar notifications and display to the android system.
Effect:
Code:
Copy codeThe Code is as follows: // Message notification bar
// Define icationicationmanager
String ns = Context. icationication_service;
Icationicationmanager mNotificationManager = (NotificationManager) getSystemService (ns );
// Define the content displayed in the notification bar
Int icon = R. drawable. icon;
CharSequence tickerText = "my notification bar title ";
Long when = System. currentTimeMillis ();
Notification notification = new Notification (icon, tickerText, when );
// Define the content to be displayed in the drop-down notification bar
Context context = getApplicationContext ();
CharSequence contentTitle = "Expand the title of my notification bar ";
CharSequence contentText = "detail in my notification bar ";
Intent icationicationintent = new Intent (this, BootStartDemo. class );
PendingIntent contentIntent = PendingIntent. getActivity (this, 0,
Icationicationintent, 0 );
Notification. setLatestEventInfo (context, contentTitle, contentText,
ContentIntent );
// Notify the user to generate a title bar Message notification using the notify method of micationicationmanager
Micationicationmanager. Y (1, notification );