Android Train—notification通知

Notification

extends Object
implements Parcelable

java.lang.Object

   ↳
android.app.Notification

Public Constructors:   比较常用的构造方法

Notification(int icon, CharSequence tickerText, long when)

Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

Public Methods

void setLatestEventInfo(

Context context,

CharSequence contentTitle,

CharSequence contentText,

PendingIntent contentIntent)

Sets the contentView field to be a view with the standard "Latest Event" layout.

 

Creating a Notification
int icon = R.drawable.notification_icon;        // icon from resources
CharSequence tickerText = "Hello";              // ticker-text
long when = System.currentTimeMillis();         // notification time
Context context = getApplicationContext();      // application Context
CharSequence contentTitle = "My notification";  // expanded message title
CharSequence contentText = "Hello World!";      // expanded message text

Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

posted @ 2015-08-14 17:03  cuiz_book  阅读(291)  评论(0编辑  收藏  举报