OngoingActivity.Builder


class OngoingActivity.Builder


Builder used to build an OngoingActivity

Note that many fields take a default value from the provided notification if not explicitly set. If set explicitly and in the notification, the value set through the Builder will be used.

The only required fields (set through the builder or the notification) are static icon and pending intent.

Summary

Public constructors

Builder(
    context: Context,
    notificationId: Int,
    notificationBuilder: NotificationCompat.Builder
)

Construct a new empty Builder, associated with the given notification.

Builder(
    context: Context,
    tag: String,
    notificationId: Int,
    notificationBuilder: NotificationCompat.Builder
)

Construct a new empty Builder, associated with the given notification.

Public functions

OngoingActivity

Combine all options provided and the information in the notification if needed, return a new OngoingActivity object.

OngoingActivity.Builder
setAnimatedIcon(animatedIcon: Icon?)

Set the animated icon that can be used on some surfaces to represent this OngoingActivity.

OngoingActivity.Builder

Set the animated icon that can be used on some surfaces to represent this OngoingActivity.

OngoingActivity.Builder
setCategory(category: String?)

Set the category of this OngoingActivity.

OngoingActivity.Builder
setContentDescription(contentDescription: String?)

Sets the content description of this OngoingActivity.

OngoingActivity.Builder

Set the corresponding LocusId of this OngoingActivity, this will be used by the launcher to identify the corresponding launcher item and display it accordingly.

OngoingActivity.Builder
setOngoingActivityId(ongoingActivityId: Int)

Give an id to this OngoingActivity, as a way to reference it in recoverOngoingActivity

OngoingActivity.Builder
setStaticIcon(staticIcon: Icon)

Set the static icon that can be used on some surfaces to represent this OngoingActivity, for example in the WatchFace in ambient mode.

OngoingActivity.Builder

Set the static icon that can be used on some surfaces to represent this OngoingActivity, for example in the WatchFace in ambient mode.

OngoingActivity.Builder
setStatus(status: Status)

Set the initial status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity.

OngoingActivity.Builder
setTitle(title: String?)

Sets the Title of this OngoingActivity.

OngoingActivity.Builder

Set the intent to be used to go back to the activity when the user interacts with the Ongoing Activity in other surfaces (for example, taps the Icon on the WatchFace).

Public constructors

Builder

Added in 1.0.0
Builder(
    context: Context,
    notificationId: Int,
    notificationBuilder: NotificationCompat.Builder
)

Construct a new empty Builder, associated with the given notification.

Parameters
context: Context

to be used during the life of this Builder, will NOT pass a reference into the built OngoingActivity

notificationId: Int

id that will be used to post the notification associated with this Ongoing Activity

notificationBuilder: NotificationCompat.Builder

builder for the notification associated with this Ongoing Activity

Builder

Added in 1.0.0
Builder(
    context: Context,
    tag: String,
    notificationId: Int,
    notificationBuilder: NotificationCompat.Builder
)

Construct a new empty Builder, associated with the given notification.

Parameters
context: Context

to be used during the life of this Builder, will NOT pass a reference into the built OngoingActivity

tag: String

tag that will be used to post the notification associated with this Ongoing Activity

notificationId: Int

id that will be used to post the notification associated with this Ongoing Activity

notificationBuilder: NotificationCompat.Builder

builder for the notification associated with this Ongoing Activity

Public functions

build

Added in 1.0.0
fun build(): OngoingActivity

Combine all options provided and the information in the notification if needed, return a new OngoingActivity object. See particular setters for information on what defaults from the notification are used.

Throws
java.lang.IllegalArgumentException

if the static icon or the touch intent are not provided.

setAnimatedIcon

Added in 1.0.0
fun setAnimatedIcon(animatedIcon: Icon?): OngoingActivity.Builder

Set the animated icon that can be used on some surfaces to represent this OngoingActivity. For example, in the WatchFace. Should be white with a transparent background, preferably an AnimatedVectorDrawable.

If not provided, or set to null, the static icon will be used.

setAnimatedIcon

Added in 1.0.0
fun setAnimatedIcon(animatedIcon: @DrawableRes Int): OngoingActivity.Builder

Set the animated icon that can be used on some surfaces to represent this OngoingActivity. For example, in the WatchFace. Should be white with a transparent background, preferably an AnimatedVectorDrawable.

If not provided, the static icon will be used.

setCategory

Added in 1.0.0
fun setCategory(category: String?): OngoingActivity.Builder

Set the category of this OngoingActivity. It may be used by the system to prioritize displaying the OngoingActivity.

If set, it Must be one of the predefined notification categories (see the CATEGORY_* constants in NotificationCompat) that best describes this OngoingActivity.

If this is not set (or null), the notification's category is used if present.

setContentDescription

Added in 1.1.0-alpha01
fun setContentDescription(contentDescription: String?): OngoingActivity.Builder

Sets the content description of this OngoingActivity. If this is set to a non-null value, it could be used by accesibility services to describe the ongoing activity.

No defaults from the notification are used for this field.

setLocusId

Added in 1.0.0
fun setLocusId(locusId: LocusIdCompat?): OngoingActivity.Builder

Set the corresponding LocusId of this OngoingActivity, this will be used by the launcher to identify the corresponding launcher item and display it accordingly.

If set to null or not set, the launcher will use heuristics to do the matching.

setOngoingActivityId

Added in 1.0.0
fun setOngoingActivityId(ongoingActivityId: Int): OngoingActivity.Builder

Give an id to this OngoingActivity, as a way to reference it in recoverOngoingActivity

setStaticIcon

Added in 1.0.0
fun setStaticIcon(staticIcon: Icon): OngoingActivity.Builder

Set the static icon that can be used on some surfaces to represent this OngoingActivity, for example in the WatchFace in ambient mode. Should be white with a transparent background, preferably a VectorDrawable.

If not set, the smallIcon of the notification will be used. If neither is set, build will throw an exception.

setStaticIcon

Added in 1.0.0
fun setStaticIcon(staticIcon: @DrawableRes Int): OngoingActivity.Builder

Set the static icon that can be used on some surfaces to represent this OngoingActivity, for example in the WatchFace in ambient mode. Should be white with a transparent background, preferably a VectorDrawable.

If not set, the smallIcon of the notification will be used. If neither is set, build will throw an exception.

setStatus

Added in 1.0.0
fun setStatus(status: Status): OngoingActivity.Builder

Set the initial status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity.

If not provided, the contentText of the notification will be used.

setTitle

Added in 1.0.0
fun setTitle(title: String?): OngoingActivity.Builder

Sets the Title of this OngoingActivity. If this is set to a non-null value, it could be used by the launcher to override the app's title.

No defaults from the notification are used for this field.

setTouchIntent

Added in 1.0.0
fun setTouchIntent(touchIntent: PendingIntent): OngoingActivity.Builder

Set the intent to be used to go back to the activity when the user interacts with the Ongoing Activity in other surfaces (for example, taps the Icon on the WatchFace).

If not set, the contentIntent of the notification will be used. If neither is set, build will throw an exception.