| java.lang.Object | |
| ↳ | android.app.Notification.Builder | 
       Builder class for
       
        
         Notification
        
       
       objects.
 Provides a convenient way to set the various fields of a
       
        
         Notification
        
       
       and generate
 content views using the platform's notification layout template. If your app supports
 versions of Android as old as API level 4, you can instead use
       
        
         NotificationCompat.Builder
        
       
       ,
 available in the
       
        Android Support
 library
       
       .
      
Example:
        Notification noti = new Notification.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .build();
       
      
     | Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          | 
        
          
          Constructs a new Builder with the defaults:
           
        
  | 
       ||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          | 
        
          
          Add an action to this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Add an action to this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Merge additional metadata into this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Combine all of the options that have been set and return a new
           
        
           
            Notification
           
          
          object.
          | 
       ||||||||||
| 
          | 
        
          
          Apply an extender to this notification builder.
          
         | 
       ||||||||||
| 
          | 
        
          
          Get the current metadata Bundle used by this notification Builder.
          
         | 
       ||||||||||
| 
          | 
        
          
          
           This method was deprecated
      in API level 16.
    Use
            
        
            
             build()
            
           
           instead.
          
          | 
       ||||||||||
| 
          | 
        
          
          Make this notification automatically dismissed when the user touches it.
          
         | 
       ||||||||||
| 
          | 
        
          
          Supply a custom RemoteViews to use instead of the platform template.
          
         | 
       ||||||||||
| 
          | 
        
          
          A small piece of additional information pertaining to this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Supply a
           
        
           
            PendingIntent
           
          
          to be sent when the notification is clicked.
          | 
       ||||||||||
| 
          | 
        
          
          Set the second line of text in the platform notification template.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the first line of text in the platform notification template.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set which notification properties will be inherited from system defaults.
          
         | 
       ||||||||||
| 
          | 
        
          
          Supply a
           
        
           
            PendingIntent
           
          
          to send when the notification is cleared explicitly by the user.
          | 
       ||||||||||
| 
          | 
        
          
          Set metadata for this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          An intent to launch instead of posting the notification to the status bar.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set this notification to be part of a group of notifications sharing the same key.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set this notification to be the group summary for a group of notifications.
          
         | 
       ||||||||||
| 
          | 
        
          
          Add a large icon to the notification (and the ticker on some devices).
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the desired color for the indicator LED on the device, as well as the
 blink duty cycle (specified in milliseconds).
          
         | 
       ||||||||||
| 
          | 
        
          
          Set whether or not this notification should not bridge to other devices.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the large number at the right-hand side of the notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set whether this is an "ongoing" notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set this flag if you would only like the sound, vibrate
 and ticker to be played if the notification is not already showing.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the priority of this notification.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the progress this notification represents.
          
         | 
       ||||||||||
| 
          | 
        
          
          Control whether the timestamp set with
           
        
           
            setWhen
           
          
          is shown
 in the content view.
          | 
       ||||||||||
| 
          | 
        
          
          A variant of
           
        
           
            setSmallIcon(int)
           
          
          that takes an additional
 level parameter for when the icon is a
          
           
            LevelListDrawable
           
          
          .
          | 
       ||||||||||
| 
          | 
        
          
          Set the small icon resource, which will be used to represent the notification in the
 status bar.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set a sort key that orders this notification among other notifications from the
 same package.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the sound to play.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the sound to play, along with a specific stream on which to play it.
          
         | 
       ||||||||||
| 
          | 
        
          
          Add a rich notification style to be applied at build time.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the third line of text in the platform notification template.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the text that is displayed in the status bar when the notification first
 arrives, and also a RemoteViews object that may be displayed instead on some
 devices.
          
         | 
       ||||||||||
| 
          | 
        
          
          Set the "ticker" text which is displayed in the status bar when the notification first
 arrives.
          
         | 
       ||||||||||
| 
          | 
        
          
          Show the
           
        
           
            when
           
          
          field as a stopwatch.
          | 
       ||||||||||
| 
          | 
        
          
          Set the vibration pattern to use.
          
         | 
       ||||||||||
| 
          | 
        
          
          Add a timestamp pertaining to the notification (usually the time the event occurred).
          
         | 
       ||||||||||
| 
         
          [Expand]
         
          
          Inherited Methods
          
         | 
       |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
         
           
         
         From class
         
          java.lang.Object
         
          | 
       |||||||||||
Constructs a new Builder with the defaults:
| priority | 
            
             
              PRIORITY_DEFAULT
             
            
            | 
          
|---|---|
| when | 
            now (
            
             
              currentTimeMillis()
             
            
            )
            | 
          
| audio stream | 
            
             
              STREAM_DEFAULT
             
            
            | 
          
| context | 
           A
           
            
             Context
            
           
           that will be used by the Builder to construct the
            RemoteViews. The Context will not be held past the lifetime of this Builder
            object.
           | 
         
|---|
Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
         Every action must have an icon (32dp square and matching the
         
          Holo
 Dark action bar
         
         visual style), a textual label, and a
         
          
           PendingIntent
          
         
         .
        
         A notification in its expanded form can display up to 3 actions, from left to right in
 the order they were added. Actions will not be displayed when the notification is
 collapsed, however, so be sure that any essential functions may be accessed by the user
 in some other way (for example, in the Activity pointed to by
         
          
           contentIntent
          
         
         ).
        
| action | The action to add. | 
|---|
Add an action to this notification. Actions are typically displayed by the system as a button adjacent to the notification content.
         Every action must have an icon (32dp square and matching the
         
          Holo
 Dark action bar
         
         visual style), a textual label, and a
         
          
           PendingIntent
          
         
         .
        
         A notification in its expanded form can display up to 3 actions, from left to right in
 the order they were added. Actions will not be displayed when the notification is
 collapsed, however, so be sure that any essential functions may be accessed by the user
 in some other way (for example, in the Activity pointed to by
         
          
           contentIntent
          
         
         ).
        
| icon | Resource ID of a drawable that represents the action. | 
|---|---|
| title | Text describing the action. | 
| intent | PendingIntent to be fired when the action is invoked. | 
Merge additional metadata into this notification.
Values within the Bundle will replace existing extras values in this Builder.
         Combine all of the options that have been set and return a new
         
          
           Notification
          
         
         object.
        
Apply an extender to this notification builder. Extenders may be used to add metadata or change options on this builder.
         Make this notification automatically dismissed when the user touches it. The
 PendingIntent set with
         
          
           setDeleteIntent(PendingIntent)
          
         
         will be sent when this happens.
        
Supply a custom RemoteViews to use instead of the platform template.
A small piece of additional information pertaining to this notification. The platform template will draw this on the last line of the notification, at the far right (to the right of a smallIcon if it has been placed there).
         Supply a
         
          
           PendingIntent
          
         
         to be sent when the notification is clicked.
 As of
         
          
           HONEYCOMB
          
         
         , if this field is unset and you
 have specified a custom RemoteViews with
         
          
           setContent(RemoteViews)
          
         
         , you can use
         
          
           RemoteViews.setOnClickPendingIntent(int,PendingIntent)
          
         
         to assign PendingIntents to individual views in that custom layout (i.e., to create
 clickable buttons inside the notification view).
        
Set the second line of text in the platform notification template.
Set the first line of text in the platform notification template.
Set which notification properties will be inherited from system defaults.
         The value should be one or more of the following fields combined with
 bitwise-or:
         
          
           DEFAULT_SOUND
          
         
         ,
         
          
           DEFAULT_VIBRATE
          
         
         ,
         
          
           DEFAULT_LIGHTS
          
         
         .
        
         For all default values, use
         
          
           DEFAULT_ALL
          
         
         .
        
         Supply a
         
          
           PendingIntent
          
         
         to send when the notification is cleared explicitly by the user.
        
Set metadata for this notification.
         A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
 current contents are copied into the Notification each time
         
          
           build()
          
         
         is
 called.
        
         Replaces any existing extras values with those from the provided Bundle.
 Use
         
          
           addExtras(Bundle)
          
         
         to merge in metadata instead.
        
An intent to launch instead of posting the notification to the status bar. Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock that the user has explicitly set to a particular time. If this facility is used for something else, please give the user an option to turn it off and use a normal notification, as this can be extremely disruptive.
| intent | The pending intent to launch. | 
|---|---|
| highPriority | Passing true will cause this notification to be sent even if other notifications are suppressed. | 
Set this notification to be part of a group of notifications sharing the same key. Grouped notifications may display in a cluster or stack on devices which support such rendering.
         To make this notification the summary for its group, also call
         
          
           setGroupSummary(boolean)
          
         
         . A sort order can be specified for group members by using
         
          
           setSortKey(String)
          
         
         .
        
| groupKey | The group key of the group. | 
|---|
         Set this notification to be the group summary for a group of notifications.
 Grouped notifications may display in a cluster or stack on devices which
 support such rendering. Requires a group key also be set using
         
          
           setGroup(String)
          
         
         .
        
| isGroupSummary | Whether this notification should be a group summary. | 
|---|
         Add a large icon to the notification (and the ticker on some devices).
 In the platform template, this image will be shown on the left of the notification view
 in place of the
         
          
           small icon
          
         
         (which will move to the right side).
        
Set whether or not this notification should not bridge to other devices.
Some notifications can be bridged to other devices for remote display. This hint can be set to recommend this notification not be bridged.
Set the large number at the right-hand side of the notification. This is equivalent to setContentInfo, although it might show the number in a different font size for readability.
Set whether this is an "ongoing" notification. Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them. They are typically used to indicate a background task that the user is actively engaged with (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).
Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing.
Set the priority of this notification.
         Set the progress this notification represents.
 The platform template will represent this using a
         
          
           ProgressBar
          
         
         .
        
         Control whether the timestamp set with
         
          
           setWhen
          
         
         is shown
 in the content view.
        
         A variant of
         
          
           setSmallIcon(int)
          
         
         that takes an additional
 level parameter for when the icon is a
         
          
           LevelListDrawable
          
         
         .
        
| icon | A resource ID in the application's package of the drawable to use. | 
|---|---|
| level | The level to use for the icon. | 
         Set the small icon resource, which will be used to represent the notification in the
 status bar.
 The platform template for the expanded view will draw this icon in the left, unless a
         
          
           large icon
          
         
         has also been specified, in which case the small
 icon will be moved to the right-hand side.
        
| icon | A resource ID in the application's package of the drawable to use. | 
|---|
Set a sort key that orders this notification among other notifications from the same package. This can be useful if an external sort was already applied and an app would like to preserve this. Notifications will be sorted lexicographically using this value, although providing different priorities in addition to providing sort key may cause this value to be ignored.
         This sort key can also be used to order members of a notification group. See
         
          
           setGroup(String)
          
         
         .
        
         Set the sound to play.
 It will be played on the
         
          
           default stream
          
         
         for notifications.
        
         Set the sound to play, along with a specific stream on which to play it.
 See
         
          
           AudioManager
          
         
         for the
         
          STREAM_
         
         constants.
        
Add a rich notification style to be applied at build time.
| style | Object responsible for modifying the notification style. | 
|---|
         Set the third line of text in the platform notification template.
 Don't use if you're also using
         
          
           setProgress(int, int, boolean)
          
         
         ; they occupy the
 same location in the standard template.
        
Set the text that is displayed in the status bar when the notification first arrives, and also a RemoteViews object that may be displayed instead on some devices.
Set the "ticker" text which is displayed in the status bar when the notification first arrives.
         Show the
         
          
           when
          
         
         field as a stopwatch.
 Instead of presenting
         
          when
         
         as a timestamp, the notification will show an
 automatically updating display of the minutes and seconds since
         
          when
         
         .
 Useful when showing an elapsed time (like an ongoing phone call).
        
         Set the vibration pattern to use.
 See
         
          
           vibrate(long[], int)
          
         
         for a discussion of the
         
          pattern
         
         parameter.
        
         Add a timestamp pertaining to the notification (usually the time the event occurred).
 It will be shown in the notification content view by default; use
         
          
           setShowWhen
          
         
         to control this.