Notification.Builder()
Notification.Builder()
extends Object
Notification
directly, Notification.Builder()
provides all necessary flags and features for Notification
Here is example usage with all the settings:
new Notification.Builder(this.getApplicationContext())
.setAutoCancel(boolean autoCancel)
.setContent(RemoteViews views)
.setContentInfo(CharSequence info)
.setContentIntent(PendingIntent intent)
.setContentText(CharSequence text)
.setContentTitle(CharSequence title)
.setDefaults(int defaults)
.setDeleteIntent(PendingIntent intent))
.setFullScreenIntent(PendingIntent intent, boolean highPriority)
.setLargeIcon(Bitmap icon)
.setLights(int argb, int onMs, int offMs)
.setNumber(int number)
.setOngoing(boolean ongoing)
.setOnlyAlertOnce(boolean onlyAlertOnce)
.setPriority(int pri)
.setProgress(int max, int progress, boolean indeterminate)
.setShowWhen(boolean show)
.setSmallIcon(int icon, int level)
.setSmallIcon(int icon)
.setSound(Uri sound)
.setSound(Uri sound, int streamType)
.setStyle(Notification.Style style)
.setSubText(CharSequence text)
.setTicker(CharSequence tickerText, RemoteViews views)
.setTicker(CharSequence tickerText)
.setUsesChronometer(boolean b)
.setVibrate(long[] pattern)
.setWhen(long when)
.addAction(int icon, CharSequence title, PendingIntent intent)
.build()
Of course, you do not have to use every settings, as most of them have defaults value, however, you have to specify below elements at least to build Notification
object. A small icon, set by setSmallIcon()
, A title, set by setContentTitle()
Detail text, set by setContentText()
Notification
extends Object
implements Parcelable
Notification
object as we can build it with new Notificaion.Build.build()
. However, since this object is implementing Parcelable
, it provides below 2 method:
void writeToParcel(Parcel parcel, int flags)
Flatten this notification from a parcel.
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
NotificationManager
extends Object
Here is general usage of
NotificationManager
Notification mNotification = new Notification.Builder(this.getApplicationContext())
.setBLAH()
.setBLAH()
.setBLAH()
.build()
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mNotification);
mNotificationManager.cancel(mId);
will dismiss based on mId
or you can use .cancelAll()
to simply kill all the notifications.
From the API level 16, Notification supports these styles, which can provides better UI experience; Style
, BigPictureStyle
, InboxStyle
, BigTextStyle
. Each style can take Notification.Builder()
, and it will generate Notification
with build()
method.
Notification.Builder
as a parameter with each Style, and you can find more details in Android Developer .