Android Message notification

Source: Internet
Author: User

Android supports toast and icationicationmanager notification methods. The former is equivalent to a timed closed dialog box, and the latter displays a message on the status bar. Both toast and notification can be canceled at any time.

 

Toast

A toast is a view containing a quick little message for the user. The toast class helps you create and show those. Toast is easy to use:

Toast. maketext (this, "Service destroyed... ", Toast. length_long). Show ();

Icationicationmanager

Icationicationmanager notifies users of events.

Icationicationmanager has three common methods:

1. Cancel (int id) cancels a previously displayed notification. If it is a short notification, it tries to hide it. If it is a persistent notification, it will be removed from the status bar.

2. cancelall () cancels all previously displayed notifications.

3. Y (int id, Notification) permanently sends the notification to the status bar.

 

// Initialize icationicationmanager:

Icationicationmanager Nm =

(Icationicationmanager) getsystemservice (notification_service );

 

 

NotificationIndicates a notification.

Notification attributes:

Audiostreamtype the type of the audio stream used when the sound starts

When a notification entry is clicked, contentintent executes the configured intent.

Contentview: When a notification is displayed on the status bar, the configured view is also displayed.

Defaults specifies the value to be set to the default value.

Deleteintent when you click the "Clear all notifications" button to delete all notifications, the configured intent is executed.

The image used by the icon status bar.

Iconlevel if there are several levels of Status Bar images, set it here.

Ledargb LED light color.

Flash time when ledoffms LED is disabled (in milliseconds)

Flash time when ledonms led starts (in milliseconds)

Number indicates the number of the event.

Sound notification sound

Information displayed when the tickertext notification is displayed in the status bar

Vibrate vibration mode.

The timestamp of the when notification.

 

Common notification methods:

Describecontents () Describe the kinds of special objects contained in this parcelable's specified alled representation.

Setlatesteventinfo (context, charsequence contenttitle, charsequence contenttext, pendingintent contentintent) sets the notification message bar Parameters

Writetoparcel (parcel, int flags) flatten this notification from a parcel.

Tostring ()................

 

Send notification to status bar:

 

Notification =NewNotification (R. drawable.Icon,

"Service started", system.Currenttimemillis());

Pendingintent contentintent = pendingintent.Getactivity(This, 0,

NewIntent (This, Main.Class), 0 );

// Must set this for content view, or will throw a exception

Notification. setlatesteventinfo (This, "Test Service ",

"Service started", contentintent );

Nm. Sort y (R. String.Hello, Notification );

 

Notification Cancellation

 

Nm. Cancel (R. String.Hello);

 

Reference: http://yuanyao.javaeye.com/blog/472332

Android Manual

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.