OngoingActivity

public final class OngoingActivity
extends Object

java.lang.Object
   ↳ androidx.wear.ongoing.OngoingActivity


Main class to access the Ongoing Activities API. It's created with the OngoingActivity.Builder. After it's created (and before building and posting the Notification) apply(Context) apply needs to be called:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)....

 OngoingActivity ongoingActivity = new OngoingActivity.Builder(context, notificationId, builder);
 ....
 ongoingActivity.apply(context);

 notificationManager.notify(notificationId, builder.build());
 
Note that if a Notification with that id was previously posted it will be replaced. If you need more than one Notification with the same ID you can use a String tag to differentiate them in both the OngoingActivity.Builder.Builder(Context, String, int, NotificationCompat.Builder) and NotificationManager.notify(String, int, Notification)

Afterward, update can be used to update the status.

If saving the OngoingActivity instance is not convenient, it can be recovered (after the notification is posted) with recoverOngoingActivity(Context)

Summary

Nested classes

class OngoingActivity.Builder

Builder used to build an OngoingActivity  

Public methods

void apply(Context context)

Notify the system that this activity should be shown as an Ongoing Activity.

Icon getAnimatedIcon()

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

String getCategory()

Get the Category of this OngoingActivity if set, otherwise the category of the corresponding notification.

LocusIdCompat getLocusId()

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

int getNotificationId()

Get the notificationId of the notification associated with this OngoingActivity.

int getOngoingActivityId()

Get the id to this OngoingActivity.

Icon getStaticIcon()

Get the static icon that can be used on some surfaces to represent this OngoingActivity.

Status getStatus()

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

String getTag()

Get the tag of the notification associated with this OngoingActivity, or null if there is none.

long getTimestamp()

Get the time (in SystemClock.elapsedRealtime() time) the OngoingActivity was built.

String getTitle()

Get the title of this OngoingActivity if set.

PendingIntent getTouchIntent()

Get 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).

static OngoingActivity recoverOngoingActivity(Context context)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance.

static OngoingActivity recoverOngoingActivity(Context context, Predicate<OngoingActivity> filter)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance.

static OngoingActivity recoverOngoingActivity(Context context, int ongoingActivityId)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance.

void update(Context context, Status status)

Update the status of this Ongoing Activity.

Inherited methods

Public methods

apply

public void apply (Context context)

Notify the system that this activity should be shown as an Ongoing Activity. This will modify the notification builder associated with this Ongoing Activity, so needs to be called before building and posting that notification.

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.

getAnimatedIcon

public Icon getAnimatedIcon ()

Get the animated icon that can be used on some surfaces to represent this OngoingActivity. For example, in the WatchFace.

Returns
Icon

getCategory

public String getCategory ()

Get the Category of this OngoingActivity if set, otherwise the category of the corresponding notification.

Returns
String

getLocusId

public LocusIdCompat getLocusId ()

Get the LocusId of this OngoingActivity, this can be used by the launcher to identify the corresponding launcher item and display it accordingly. If not set, returns the one in the corresponding Notification.

Returns
LocusIdCompat

getNotificationId

public int getNotificationId ()

Get the notificationId of the notification associated with this OngoingActivity.

Returns
int

getOngoingActivityId

public int getOngoingActivityId ()

Get the id to this OngoingActivity. This id is used to reference it in recoverOngoingActivity(Context, int)

Returns
int

getStaticIcon

public Icon getStaticIcon ()

Get the static icon that can be used on some surfaces to represent this OngoingActivity. For example in the WatchFace in ambient mode. If not set, returns the small icon of the corresponding Notification.

Returns
Icon

getStatus

public Status getStatus ()

Get the status of this ongoing activity, the status may be displayed on the UI to show progress of the Ongoing Activity. If not set, returns the content text of the corresponding Notification.

Returns
Status

getTag

public String getTag ()

Get the tag of the notification associated with this OngoingActivity, or null if there is none.

Returns
String

getTimestamp

public long getTimestamp ()

Get the time (in SystemClock.elapsedRealtime() time) the OngoingActivity was built.

Returns
long

getTitle

public String getTitle ()

Get the title of this OngoingActivity if set.

Returns
String

getTouchIntent

public PendingIntent getTouchIntent ()

Get 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, returns the touch intent of the corresponding Notification.

Returns
PendingIntent

recoverOngoingActivity

public static OngoingActivity recoverOngoingActivity (Context context)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance. Note that if there is more than one Ongoing Activity active you have not guarantee over which one you get, you need to use one of the other variations of this method.

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.

Returns
OngoingActivity the Ongoing Activity or null if not found

recoverOngoingActivity

public static OngoingActivity recoverOngoingActivity (Context context, 
                Predicate<OngoingActivity> filter)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance.

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.

filter Predicate: used to find the required OngoingActivity.

Returns
OngoingActivity the Ongoing Activity or null if not found

recoverOngoingActivity

public static OngoingActivity recoverOngoingActivity (Context context, 
                int ongoingActivityId)

Convenience method for clients that don’t want to / can’t store the OngoingActivity instance.

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.

ongoingActivityId int: the id of the Ongoing Activity to retrieve, set in OngoingActivity.Builder.setOngoingActivityId(int)

Returns
OngoingActivity the Ongoing Activity or null if not found

update

public void update (Context context, 
                Status status)

Update the status of this Ongoing Activity. Note that this may post the notification updated with the new information.

Parameters
context Context: May be used to access system services. A reference will not be kept after this call returns.

status Status: The new status of this Ongoing Activity.