Android Programming Press on the image to return to the main documentation page.

NotificationBuilder

Written by BarxDroid

List of types:

NotificationBigPictureStyle
NotificationBigTextStyle
NotificationBuilder
NotificationCustomLayout
NotificationInboxStyle
NotificationRemoteInput
NotificationWearableExtender

NotificationBigPictureStyle


Events:

None

Members:


  BigContentTitle As String [write only]

  BigPicture As android.graphics.Bitmap [write only]

  Initialize

  IsInitialized As Boolean

  SummaryText As String [write only]

Members description:

BigContentTitle As String [write only]
Overrides the ContentTitle set in the Notification Builder.
BigPicture As android.graphics.Bitmap [write only]
Provides the Big Picture to be used in the BigPicture notification.
Initialize
Helper class for generating large-format notifications that include a large image attachment.
If the platform does not provide large-format notifications, this method has no effect.
IsInitialized As Boolean
SummaryText As String [write only]
Sets the first line of text after the details section

NotificationBigTextStyle


Events:

None

Members:


  BigContentTitle As String [write only]

  BigText As String [write only]

  Initialize

  IsInitialized As Boolean

  SummaryText As String [write only]

Members description:

BigContentTitle As String [write only]
Overrides the ContentTitle set in the Notification Builder.
BigText As String [write only]
Provides the longer text to displayed in the content area. Replaces ContextText.
Initialize
Helper class for generating large-format notifications that include a lot of text.
If the platform does not provide large-format notifications, this method has no effect.
IsInitialized As Boolean
SummaryText As String [write only]
Sets the first line of text after the details section

NotificationBuilder


Permissions:

android.permission.VIBRATE

Events:

None

Members:


  AddAction (icon As String, title As String, tag As String, Activity As Object)

  AddAction2 (icon As String, title As String, tag As String, Service As Object)

  AutoCancel As Boolean [write only]

  Cancel (id As Int)

  ContentInfo As String [write only]

  ContentText As String [write only]

  ContentTitle As String [write only]

  CustomLayout As android.widget.RemoteViews [write only]

  CustomSound As String [write only]

  CustomVibrate() As Long [write only]

  DefaultLight As Boolean [write only]

  DefaultSound As Boolean [write only]

  DefaultVibrate As Boolean [write only]

  Extend (NotificationWearableExtender As android.support.v4.app.NotificationCompat.Extender)

  GetNotification As android.app.Notification

  Group As String [write only]

  GroupSummary As Boolean [write only]

  Initialize

  IsInitialized As Boolean

  LargeIcon As android.graphics.Bitmap [write only]

  LocalOnly As Boolean [write only]

  Notify (id As Int)

  Number As Int

  OnGoingEvent As Boolean [write only]

  OnlyAlertOnce As Boolean [write only]

  Priority As Int [write only]

  setActivity (Activity As Object)

  setCustomLight (argb As Int, onMs As Int, offMs As Int)

  setDeleteActivity (Activity As Object)

  setDeleteService (Service As Object)

  setIntent (intent As android.content.Intent)

  setParentActivity (Activity As Object)

  setProgress (Max As Int, Progress As Int, Indeterminate As Boolean)

  setSmallIcon2 (Icon As String, Level As Int)

  SetStyle (style As android.support.v4.app.NotificationCompat.Style)

  ShowTime As Boolean [write only]

  SmallIcon As String [write only]

  SortKey As String [write only]

  SubText As String [write only]

  Tag As String [write only]

  Ticker As String [write only]

  UsesChrono As Boolean [write only]

  When As Long [write only]

Members description:

AddAction (icon As String, title As String, tag As String, Activity As Object)
Adds an Action to the notification.

Actions are buttons displayed on the notification that can allow users to do something without starting the app. e.g Call back a missed call, pause a sound track, etc

The icon file should manually copied to the Objects\res\drawable\ folder and set to read-only.
The file name is case sensitive and should not contain the file extension.
If tag is set to "" then it will default to the passed title.

tags are named 'Notification_Action_Tag'

Use AddAction2 to pass a Service module instead of an Activity.

MAXIMUM of 3 Actions can be added to each notification.

API 16+
AddAction2 (icon As String, title As String, tag As String, Service As Object)
Similar to AddAction, but you pass a Service Module rather than an Activity Module.
AutoCancel As Boolean [write only]
Sets whether the notification will be cancelled automatically when the user taps it.
Cancel (id As Int)
Cancels the notification with the given id
ContentInfo As String [write only]
Sets the text in the right-hand side of the notification.
ContentText As String [write only]
Set the text in the Text field.
ContentTitle As String [write only]
Sets the text in the Title field.
CustomLayout As android.widget.RemoteViews [write only]
Sets a custom layout for the notification.

Pass a NotificationCustomLayout object.

API 11+
CustomSound As String [write only]
Sets a custom sound to be played on new notification

Example:
cn.CustomSound = "file:///sdcard/notification/ringer.mp3"
CustomVibrate() As Long [write only]
Sets a custom vibrate pattern for new notification
The Array of values can be as long as you wish.
The first Value is the pause before vibration starts, then its ON, OFF, ON, OFF,........

Example:

Dim nb as NotificationBuilder
Dim v() as Long

v = Array as Long(0, 100, 200, 300, 400)
nb.CustomVibrate(v)
DefaultLight As Boolean [write only]
Sets whether the notification will show a light.

Setting to True will over ride any custom light settings.

Example:
nb.DefaultLight = True
DefaultSound As Boolean [write only]
Sets whether the notification will play a sound.

Note: Setting to True will over ride any custom sound set.

Example:
nb.DefaultSound = False
DefaultVibrate As Boolean [write only]
Sets whether the notification will vibrate the device.

Note: Setting to True will over ride any custom vibration settings.

Example:
nb.Vibrate = True
Extend (NotificationWearableExtender As android.support.v4.app.NotificationCompat.Extender)
Applies an Extender to the Notification.

i.e NotificationWearableExtender is used to extend the notification with functions only available to Wearable devices.
GetNotification As android.app.Notification
Gets the Notification Object. Useful for things like Foreground Services
Group As String [write only]
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
nb.GroupSummary = True
A sort order can be specified by using
nb.SortKey(Key)
GroupSummary As Boolean [write only]
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.

The GroupSummary notification will not show on the notification stack on Wearables, but will show as the only notification on handheld devices.
See URL
Click

Requires a group key also be set using
nb.Group(GroupKey)
Initialize
IsInitialized As Boolean
LargeIcon As android.graphics.Bitmap [write only]
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).
LocalOnly As Boolean [write only]
Sets whether or not this notification is only relevant to the current device.
Some notifications can be bridged to other devices for remote display. I.E Wear Devices
Notify (id As Int)
Displays the notification.
id - The notification id. This id can be used later to update the notification (by calling Notify again with the same id),
or to cancel the notification
Number As Int
Gets or Sets the number to be shown on the notification.
This is useful to represent multiple events in a single notification.
OnGoingEvent As Boolean [write only]
Sets whether the notification is an 'ongoing event'.
The notification will be shown in the ongoing section and will not be cleared.
OnlyAlertOnce As Boolean [write only]
Sets whether the notification will only play sound / vibrate /show light if the notification is not already showing.
Priority As Int [write only]
Experimental - Googles' notes:-
'Set the relative priority for this notification.
Priority is an indication of how much of the user's valuable attention should be consumed by this notification.
Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification.
The system sets a notification's priority based on various factors including the setPriority value.
The effect may differ slightly on different platforms.'

API 16+
setActivity (Activity As Object)
Sets the activity that will be launched when the Notification is tapped.

Use nb.Intent to use your own calling intent
setCustomLight (argb As Int, onMs As Int, offMs As Int)
Sets a custom argb value for the notification light, also sets the rates at which it flashes.
argb - The color that the devices led will flash.
onMs - The time in milliseconds that the led will stay on each blink.
offMs - The time in millliseconds that the led will be off after each blink.

NOTE: Not all devices will honour these settings, it is dependent on hardware abilities.
setDeleteActivity (Activity As Object)
Experimental - Setting a DeleteActivity will (should) show the activity when the user clears the notification manually.

API 11+
setDeleteService (Service As Object)
Experimental - Setting a DeleteService will (should) show the service when the user clears the notification manually.

A{PI 11+
setIntent (intent As android.content.Intent)
Sets the Intent that will be called when the Notification is tapped.

Use nb.Activity to call an activity in your project.
setParentActivity (Activity As Object)
Sets a Parent Activity to add to the 'Back Stack'. If this method is used then once you have entered
an Activity from your notification, pressing back will return to the Parent Activity, rather than exiting the App.

API 11+
setProgress (Max As Int, Progress As Int, Indeterminate As Boolean)
Sets the progress the notification represents. This may be shown as a progress bar dependent on SDK version.

API 14+
setSmallIcon2 (Icon As String, Level As Int)
Similar to .SmallIcon but takes a 'Level' parameter for when a LevelListDrawable is used.
SetStyle (style As android.support.v4.app.NotificationCompat.Style)
Add an extended style to the notification.

Must be passed a style object:-
NotificationInboxStyle
NotificationBigTextStyle
NotificationBigPictureStyle

API 16+
ShowTime As Boolean [write only]
Sets whether the time stamp is shown on the notification.
Default is 'true'
SmallIcon As String [write only]
Sets the Small Icon to be displayed.
The image file should manually copied to the Objects\res\drawable\ folder and set to read-only.
The file name is case sensitive and should not contain the file extension.
You can use "icon" to use the applications icon.
SortKey As String [write only]
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.

This sort key can also be used to order members of a notification group.
SubText As String [write only]
Set the third line of text in the platform notification template.
Don't use if you're also using setProgress(); they occupy the same location in the standard template.
If the platform does not provide large-format notifications, this method has no effect. The third line of text only appears in expanded view.

API 16+
Tag As String [write only]
The Tag is a string that can be extracted later on Activity_Resume.
This can be used to determine which notification has been clicked by the user when multiple notifications exist.

Example of extracting the Tag:

Sub Activity_Resume
Dim in as Intent
Dim intentExtra as String

in = Activity.GetStartingIntent
If in.HasExtra("Notification_Tag") Then
intentExtra = in.GetExtra("Notification_Tag")
End If
End Sub
Ticker As String [write only]
Sets the Ticker Text which shows along side the status bar icon of new Notifications.
UsesChrono As Boolean [write only]
If set the timestamp place on the notification will be used as a stopwatch. It will automatically update the minutes and seconds since .When()

API 16+
When As Long [write only]
Sets the time stamp that shows on the notification. This should indicate the time the event occurred.
Default is the current time.
Setting to 0 will reset to current time.

NotificationCustomLayout


Events:

None

Members:


  BuildLayout As android.widget.RemoteViews

  EXPANDED_HEIGHT As Int

  Initialize (LayoutFile As String)

  Initialize2 (Panel As String)

  IsInitialized As Boolean

  NORMAL_HEIGHT As Int

  setEnableClickEvent (View As String, Activity As Object, Tag As String)

  SetImage (Image As String, Bitmap As android.graphics.Bitmap)

  SetProgress (ProgressBar As String, MaxProgress As Int, Progress As Int, Indeterminate As Boolean)

  SetTextColor (TextField As String, Color As Int)

  SetTextField (TextField As String, Text As String)

Members description:

BuildLayout As android.widget.RemoteViews
Returns the CustomLayout object
EXPANDED_HEIGHT As Int
Initialize (LayoutFile As String)
Initilizes the Object

LayoutFile - The name of the .xml file containing the layout (do not add '.xml')
Initialize2 (Panel As String)
!!! NOT WORKING !!!

Initializes the object, using a Panel of views for the layout
IsInitialized As Boolean
NORMAL_HEIGHT As Int
setEnableClickEvent (View As String, Activity As Object, Tag As String)
Enables the Click action for a view in a custom layout.

View - The name of the view as defined in the xml layout
Activity - The activity that will be launched when the view is clicked (Maybe service will work too)
Tag - The tag that will be returned as an extra in the starting intent

Implements setOnClickPendingIntent
Android V3+
SetImage (Image As String, Bitmap As android.graphics.Bitmap)
Sets an image within a custom layout

Image - The name of the image element as defined in the xml layout
Bitmap - The image to apply
SetProgress (ProgressBar As String, MaxProgress As Int, Progress As Int, Indeterminate As Boolean)
Sets the parameters for a progress bar used in a notification

ProgressBar - The name of the progress bar as defined in the xml layout
MaxProgress - the upper limit of the progress bar. A good value is 100
Progress - the current level of progress to be shown. Must be <= maxProgress.
Indeterminate - set the progress bar as indeterminate
SetTextColor (TextField As String, Color As Int)
Sets the color of the text in a text field in a custom layout

TextField - The name of the text element as defined in the xml layout
Color - The color that will be assigned to the text element
SetTextField (TextField As String, Text As String)
Sets the text field in a custom layout

TextField - The name of the text element as defined in the xml layout
Text - The string that will be assigned to the text element

NotificationInboxStyle


Events:

None

Members:


  AddLine As String [write only]

  BigContentTitle As String [write only]

  Initialize

  IsInitialized As Boolean

  SummaryText As String [write only]

Members description:

AddLine As String [write only]
Adds a line to the details section.
You can add a MAXIMUM of 5 lines.
BigContentTitle As String [write only]
Overrides the ContentTitle set in the Notification Builder.
Initialize
Helper class for generating large-format notifications that include a list of (up to 5) strings.
If the platform does not provide large-format notifications, this method has no effect
IsInitialized As Boolean
SummaryText As String [write only]
Sets the first line of text after the details section

NotificationRemoteInput


Events:

None

Members:


  Choices() As String [write only]

  GetRemoteInput (intent As android.content.Intent, key As String) As String

  Initialize (Label As String)

  IsInitialized As Boolean

  Label As String [write only]

Members description:

Choices() As String [write only]
Set a list of preset choices to show when requesting for voice input

example:
RemoteInput1.Choices = Array as String("Yes", "No", "Maybe")
GetRemoteInput (intent As android.content.Intent, key As String) As String
Extracts a RemoteInput (voice) string from starting intent

Use this in the Activity_Resume of the Activity called by the Action.
Example:


Dim In as intent
In = Activity.GetStartingIntent
If In.HasExtra("Notification_Wear_Action_Tag") Then
If In.GetExtra("Notification_Wear_Action_Tag") = Tag Then 'Tag set when adding Action to Notification
Dim Rem as NotificationRemoteInput

ToastMessageShow(Rem.GetRemoteInput(In, Label), false) 'Label set on Initialize
End If
End If
Initialize (Label As String)
Initializes the object.

Label - Used to retrieve the reply later.

See GetRemoteInput for details on how to get the input.

NOTE: you do not need to call Initialize in order to use GetRemoteInput.
IsInitialized As Boolean
Label As String [write only]
Sets the label to show when requesting for voice input

NotificationWearableExtender


Events:

None

Members:


  AddAction (icon As String, title As String, tag As String, object As Object)

  AddAction2 (icon As String, title As String, tag As String, object As Object, RemoteInput As android.support.v4.app.RemoteInput.Builder)

  AddPage (Page As android.support.v4.app.NotificationCompat.Builder)

  Background As android.graphics.Bitmap

  BOTTOM As Int

  CENTER_VERTICAL As Int

  ClearActions

  ClearPages

  ContentAction As Int [write only]

  ContentIcon As String [write only]

  ContentIconGravity As Int [write only]

  ContentIntentAvailableOffline As Boolean [write only]

  CustomContentHeight As Int

  CustomSizePreset As Int

  END As Int

  Gravity As Int [write only]

  HideIcon As Boolean [write only]

  Initialize

  IsInitialized As Boolean

  setDisplayIntent (Activity As Object)

  ShowBackgroundOnly As Boolean [write only]

  SIZE_DEFAULT As Int

  SIZE_FULL_SCREEN As Int

  SIZE_LARGE As Int

  SIZE_MEDIUM As Int

  SIZE_SMALL As Int

  SIZE_XSMALL As Int

  START As Int

  StartScrollBottom As Boolean [write only]

  TOP As Int

Members description:

AddAction (icon As String, title As String, tag As String, object As Object)
Similar to NotificatioBuilder.AddAction, but the Action will show on Wear Devices only.
If this method is used the Wear device will NOT display any of the other actions.

Tags are named 'Notification_Wear_Action_Tag
AddAction2 (icon As String, title As String, tag As String, object As Object, RemoteInput As android.support.v4.app.RemoteInput.Builder)
Similar to AddAction but allows you to pass a RemoteInput object for voice input.
AddPage (Page As android.support.v4.app.NotificationCompat.Builder)
Adds an additional page to notifications shown on Wear Device

Page - A new notification.

Example:


Dim Notification1, Notification2 as NotificationBuilder
'code to build notifications
...
Notification1.AddPage(Notification2.build())
...
Background As android.graphics.Bitmap
Set or Get the background of the Wear Notification (no matter what the Style)
BOTTOM As Int
CENTER_VERTICAL As Int
ClearActions
Clears any previously added Actions.
ClearPages
Clears any previously added Pages.
ContentAction As Int [write only]
Sets the action to be clickable with the content of this notification. i.e. When you click the main notification, it will trigger the Action.

This action will no longer display separately from this notification's content.
For notifications with multiple pages, child pages can also have content actions set,
although the list of available actions comes from the main notification and not from the child page's notification.

ActionIndex is the ID of the Action to use. ID's start at 0
ContentIcon As String [write only]
Sets the Icon that goes with the content of this notification

The image file should manually copied to the Objects\res\drawable\ folder and set to read-only.
The file name is case sensitive and should not contain the file extension.
You can use "icon" to use the applications icon.
ContentIconGravity As Int [write only]
Sets the gravity for the ContentIcon.
Supported values START, END
Use the built in constants. e.g WearExtender.START
ContentIntentAvailableOffline As Boolean [write only]
Sets whether the content intent is available when the wearable device is not connected to a companion device.
CustomContentHeight As Int
Sets or Gets the custom height for the display of this notifications content.

NOTE: This option is only available for custom display notifications created using DisplayIntent
CustomSizePreset As Int
Sets or Gets the custom size preset for the display of this notification out of the available presents.
Use the built in constants. e.g. WearExtender1.SIZE_LARGE
Possible values - SIZE_DEFAULT, SIZE_FULL_SCREEN, SIZE_LARGE, SIZE_MEDIUM, SIZE_SMALL, SIZE_XSMALL
END As Int
Gravity As Int [write only]
Sets the gravity of the Notification on the device.
Supported values BOTTOM, CENTER_VERTICALLY, TOP
Use the built in constants. e.g WearExtender.TOP
HideIcon As Boolean [write only]
Hides the Icon if set to true.
Initialize
Initializes the object
IsInitialized As Boolean
setDisplayIntent (Activity As Object)
Googles Docs
------------
Set an activity to be displayed while viewing the notification.

My Version after doing a little research
----------------------------------------
When creating a notification directly from an App on the Wear device, you can use custom layouts. This is done by creating the layout
in an activity in the App. Then call this method, passing the layout activity as the Parameter.

The activity to launch needs to allow embedding, must be exported and should have an empty task affinity.
It is also recommended to use the device default light theme.
This is achieved by adding the following to the Manifest Editor

[code]
SetActivityAttribute (DisplayActivity, android:exported, "true")
SetActivityAttribute (DisplayActivity, android:allowEmbedded, "true")
SetActivityAttribute (DisplayActivity, android:taskAffinity, "")
SetActivityAttribute (DisplayActivity, android:theme, "@android:style/Theme.DeviceDefault.Light")
[/code]
ShowBackgroundOnly As Boolean [write only]
Only the background image of this notification should be displayed, and other semantic content should be hidden.
This method only applies to sub Pages.
SIZE_DEFAULT As Int
SIZE_FULL_SCREEN As Int
SIZE_LARGE As Int
SIZE_MEDIUM As Int
SIZE_SMALL As Int
SIZE_XSMALL As Int
START As Int
StartScrollBottom As Boolean [write only]
Sets whether the scrolling position for the contents of this notification should start at the bottom of the contents
instead of the top when the contents are too long to display within the screen. Default is false (start scroll at the top)
TOP As Int

Top