TileService
public abstract class TileService extends Service
| java.lang.Object | ||||
| ↳ | android.content.Context | |||
| ↳ | android.content.ContextWrapper | |||
| ↳ | android.app.Service | |||
| ↳ | androidx.wear.tiles.TileService |
Base class for a service providing data for an app tile.
A provider service must implement onTileRequest and onTileResourcesRequest to respond to requests for updates from the system.
The manifest declaration of this service must include an intent filter for ACTION_BIND_TILE_PROVIDER.
The manifest entry should also include
android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER" to ensure that only the system can bind to it.
Summary
Constants |
|
|---|---|
static final String |
ACTION_BIND_TILE_PROVIDER = "androidx.wear.tiles.action.BIND_TILE_PROVIDER"The intent action used to send update requests to the provider. |
static final String |
EXTRA_CLICKABLE_ID = "androidx.wear.tiles.extra.CLICKABLE_ID"The ID for the Intent extra containing the ID of the Clickable. |
static final String |
METADATA_PREVIEW_KEY = "androidx.wear.tiles.PREVIEW"The name of the metadata key that should contain a drawable to be presented as a Tile preview. |
Public constructors |
|---|
Public methods |
|
|---|---|
static @NonNull ListenableFuture<List<ActiveTileIdentifier>> |
getActiveTilesAsync(@NonNull Context context, @NonNull Executor executor)Returns the list of active tiles belonging to the passed |
static @NonNull TileUpdateRequester |
getUpdater(@NonNull Context context)Gets an instance of |
@Nullable IBinder |
Protected methods |
|
|---|---|
@NonNull ListenableFuture<Void> |
@MainThreadCalled when the system sends a batch of Tile interaction events that happened since the last time this method was called. |
@NonNull ListenableFuture<ResourceBuilders.Resources> |
@MainThreadThis method is deprecated. Use |
void |
@MainThreadCalled when a tile provided by this Tile Provider is added to the carousel. |
void |
@MainThreadThis method is deprecated. |
void |
@MainThreadThis method is deprecated. |
void |
@MainThreadCalled when a tile provided by this Tile Provider is removed from the carousel. |
abstract @NonNull ListenableFuture<TileBuilders.Tile> |
@MainThreadCalled when the system is requesting a new timeline from this Tile Provider. |
@NonNull ListenableFuture<ResourceBuilders.Resources> |
@MainThreadCalled when the system is requesting a resource bundle from this Tile Provider. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||
|
Constants
ACTION_BIND_TILE_PROVIDER
public static final String ACTION_BIND_TILE_PROVIDER = "androidx.wear.tiles.action.BIND_TILE_PROVIDER"
The intent action used to send update requests to the provider. Tile provider services must declare an intent filter for this action in the manifest.
EXTRA_CLICKABLE_ID
public static final String EXTRA_CLICKABLE_ID = "androidx.wear.tiles.extra.CLICKABLE_ID"
The ID for the Intent extra containing the ID of the Clickable.
METADATA_PREVIEW_KEY
public static final String METADATA_PREVIEW_KEY = "androidx.wear.tiles.PREVIEW"
The name of the metadata key that should contain a drawable to be presented as a Tile preview.
Public constructors
Public methods
getActiveTilesAsync
public static @NonNull ListenableFuture<List<ActiveTileIdentifier>> getActiveTilesAsync(@NonNull Context context, @NonNull Executor executor)
Returns the list of active tiles belonging to the passed context's package name. A tile is considered to be active if it is present in the carousel.
The result reflects the state of carousel at the time the call was made, which might've changed by the time the result is received. onTileAddEvent and onTileRemoveEvent should be used instead for live updates.
Compatibility behavior:
On SDKs older than U, this method is a best-effort to match platform behavior, but may not always return all tiles present in the carousel. The possibly omitted tiles being the pre-installed tiles, all tiles if the user has cleared the app data, or the tiles a user hasn't visited in the last 60 days, while tiles removed by an app update may be shown as active for 60 days afterwards.
| Parameters | |
|---|---|
@NonNull Context context |
The application context. |
@NonNull Executor executor |
The executor on which methods should be invoked. To dispatch events through the main thread of your application, you can use |
| Returns | |
|---|---|
@NonNull ListenableFuture<List<ActiveTileIdentifier>> |
A list of |
getUpdater
public static @NonNull TileUpdateRequester getUpdater(@NonNull Context context)
Gets an instance of TileUpdateRequester to allow a Tile Provider to notify the tile's renderer that it should request a new Timeline from this TileService.
Protected methods
onRecentInteractionEventsAsync
@MainThread
protected @NonNull ListenableFuture<Void> onRecentInteractionEventsAsync(
@NonNull List<EventBuilders.TileInteractionEvent> events
)
Called when the system sends a batch of Tile interaction events that happened since the last time this method was called. The time between calls to this method may vary, do not depend on it for time-sensitive or critical tasks.
Interaction events represent user direct interaction with a tile, when a tile comes into view (enter event) or when the tiles goes out of view (leave event).
The returned future must complete after at most 10 seconds from the moment this method is called (exact timeout length subject to change, but 10 seconds is guaranteed).
This method is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull List<EventBuilders.TileInteractionEvent> events |
A list of |
@MainThread
protected @NonNull ListenableFuture<ResourceBuilders.Resources>onResourcesRequest(
@NonNull RequestBuilders.ResourcesRequest requestParams
)
Called when the system is requesting a resource bundle from this Tile Provider. The returned future must complete after at most 10 seconds from the moment this method is called (exact timeout length subject to change).
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull RequestBuilders.ResourcesRequest requestParams |
Parameters about the request. See |
onTileAddEvent
@MainThread
protected void onTileAddEvent(@NonNull EventBuilders.TileAddEvent requestParams)
Called when a tile provided by this Tile Provider is added to the carousel.
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull EventBuilders.TileAddEvent requestParams |
Parameters about the request. See |
@MainThread
protected voidonTileEnterEvent(@NonNull EventBuilders.TileEnterEvent requestParams)
Called when a tile provided by this Tile Provider becomes into view, on screen.
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull EventBuilders.TileEnterEvent requestParams |
Parameters about the request. See |
@MainThread
protected voidonTileLeaveEvent(@NonNull EventBuilders.TileLeaveEvent requestParams)
Called when a tile provided by this Tile Provider goes out of view, on screen.
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull EventBuilders.TileLeaveEvent requestParams |
Parameters about the request. See |
onTileRemoveEvent
@MainThread
protected void onTileRemoveEvent(@NonNull EventBuilders.TileRemoveEvent requestParams)
Called when a tile provided by this Tile Provider is removed from the carousel.
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull EventBuilders.TileRemoveEvent requestParams |
Parameters about the request. See |
onTileRequest
@MainThread
protected abstract @NonNull ListenableFuture<TileBuilders.Tile> onTileRequest(@NonNull RequestBuilders.TileRequest requestParams)
Called when the system is requesting a new timeline from this Tile Provider. The returned future must complete after at most 10 seconds from the moment this method is called (exact timeout length subject to change).
Note that this is called from your app's main thread, which is usually also the UI thread.
| Parameters | |
|---|---|
@NonNull RequestBuilders.TileRequest requestParams |
Parameters about the request. See |
onTileResourcesRequest
@MainThread
protected @NonNull ListenableFuture<ResourceBuilders.Resources> onTileResourcesRequest(
@NonNull RequestBuilders.ResourcesRequest requestParams
)
Called when the system is requesting a resource bundle from this Tile Provider. This can happen on the first time a Tile is being loaded or whenever the resource version requested by a Tile (in onTileRequest) changes.
If using methods that accept ProtoLayoutScope for creating image elements, this method shouldn't be implemented as resources bundle will be automatically registered by the ProtoLayoutScope itself.
The returned future must complete after at most 10 seconds from the moment this method is called (exact timeout length subject to change).
Note that this is called from your app's main thread, which is usually also the UI thread.
If onTileResourcesRequest is not implemented, the TileService will fallback to onResourcesRequest.
| Parameters | |
|---|---|
@NonNull RequestBuilders.ResourcesRequest requestParams |
Parameters about the request. See |