Android notication usage

Source: Internet
Author: User

Android notication usage

private void sendNotification() {// TODO Auto-generated method stubNotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);Notification notification = new Notification();notification.icon = R.drawable.ic_launcher;notification.tickerText = "I am in the state bar!";notification.audioStreamType = android.media.AudioManager.ADJUST_LOWER;Intent intent = new Intent(this, secondActivity.class );PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);notification.setLatestEventInfo(this, "Content Title","Content", pendingIntent);manager.notify(1,notification);}

Code explanation:

1: Obtain icationicationmanager:

Icationicationmanager m_notificationmanager = (notificationmanager) This. getsystemservice (icationication_service );

2: Define a notification:

Notification m_notification = new notification ();

3: set various attributes of notification:

// Set the notification icon

M_icationication.icon = R. drawable. Icon;

// Content displayed when we click the notification

M_icationication.tickertext = "button1 notification content .....";

// Send the default sound during notification

M_icationication.defaults = notification. default_sound;

// Set notification display parameters

Intent m_intent = new intent (icationicationdemo. This, desactivity. Class );

Pendingintent m_pendingintent = pendingintent. getactivity (icationicationdemo. This, 0, m_intent, 0 );

M_icationication.setlatesteventinfo (icationicationdemo. This, "button1", "button1 notification", m_pendingintent );

// Start Execution Notification

M_icationicationmanager.policy (0, m_notification );

4: Now that you can delete a new one.

M_icationicationmanager.cancel (0 );

This 0 is an idnumber, which is the same as the first parameter 0 of policy.

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.