Android Implementation status bar Add Icon function instance _android

Source: Internet
Author: User

The example in this article tells the Android implementation status bar to add an icon function. Share to everyone for your reference. as follows:

private void Shownotification () {//Create a Notificationmanager reference Notificationmanager Notificationmanager = (notificati 
 Onmanager) AutoFile.this.getSystemService (Android.content.Context.NOTIFICATION_SERVICE); Defines the various attributes of Notification Notification Notification = new Notification (R.drawable.dvd, "Sound player", System.currenttimemill 
 Is ()); Notification.flags |= notification.flag_ongoing_event; Place this notice in the "ongoing", the "Running" group, in the notification bar notification.flags |= notification.flag_no_clear; 
 Indicates that after clicking on the "clear notice" in the notification bar, this notice is not cleared, often with flag_ongoing_event to use Notification.flags |= notification.flag_show_lights; 
 Notification.defaults = notification.default_lights; 
 Notification.ledargb = Color.Blue; 
 NOTIFICATION.LEDONMS = 5000; Set the event message for the notification charsequence contenttitle = "The sounds of nature are playing ..."; Notice Bar title Charsequence ContentText = "Ameyume"; Notification bar content Intent notificationintent = new Intent (autofile.this, Myplayerservice.class); Click on the notification to jump to the activity pendingintent contentitent = pendingintent.getactivity (autofIle.this, 0, notificationintent, 0); 
 Notification.setlatesteventinfo (Autofile.this, Contenttitle, ContentText, contentitent); 
Pass the notification to Notificationmanager notificationmanager.notify (0, notification); 

 }

To remove an icon, use the following code:

After startup delete We define the notification 
Notificationmanager Notificationmanager = (Notificationmanager) this 
 . Getsystemservice ( Notification_service); 
Notificationmanager.cancel (0);

I hope this article will help you with your Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.