Material3TileService


public abstract class Material3TileService extends TileService


Base class for a service providing data for an app's tile that includes ProtoLayoutScope for automatic resource registration and opinionated MaterialScope for Material3 styling of components and layout.

A provider service must implement tileResponse to respond to requests for updates from the system. Tile response should contain layout and resources in the same response.

The manifest declaration of this service must include an intent filter for TileService.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.

import androidx.wear.protolayout.TimelineBuilders.Timeline
import androidx.wear.protolayout.layout.imageResource
import androidx.wear.protolayout.layout.lottieResource
import androidx.wear.protolayout.material3.ColorScheme
import androidx.wear.protolayout.material3.MaterialScope
import androidx.wear.protolayout.material3.backgroundImage
import androidx.wear.protolayout.material3.imageButton
import androidx.wear.protolayout.material3.primaryLayout
import androidx.wear.protolayout.modifiers.clickable
import androidx.wear.tiles.Material3TileService
import androidx.wear.tiles.RequestBuilders.TileRequest
import androidx.wear.tiles.TileBuilders.Tile

object : Material3TileService(defaultColorScheme = myColorScheme) {
        override suspend fun MaterialScope.tileResponse(requestParams: TileRequest): Tile =
            Tile.Builder()
                .setTileTimeline(
                    Timeline.fromLayoutElement(
                        primaryLayout(
                            mainSlot = {
                                imageButton(
                                    onClick = clickable(),
                                    backgroundContent = {
                                        backgroundImage(
                                            resource =
                                                imageResource(
                                                    lottie =
                                                        lottieResource(rawResourceId = lottieResId)
                                                )
                                        )
                                    },
                                )
                            }
                        )
                    )
                )
                .build()
    }

Summary

Public constructors

Material3TileService(
    boolean allowDynamicTheme,
    @NonNull ColorScheme defaultColorScheme,
    CoroutineScope serviceScope
)

Public methods

void
void

Protected methods

abstract @NonNull TileBuilders.Tile
tileResponse(
    @NonNull MaterialScope receiver,
    @NonNull RequestBuilders.TileRequest requestParams
)

Called when the system is requesting a new timeline from this Tile Provider.

Inherited methods

From android.content.Context
boolean
final int
getColor(int p0)
final @NonNull ColorStateList
final @Nullable Drawable
getDrawable(int p0)
final @NonNull String
getString(int p0)
final @NonNull String
getString(int p0, @NonNull Object... p1)
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> p0)
final @NonNull CharSequence
getText(int p0)
final @NonNull TypedArray
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int p0, @NonNull int[] p1)
final @NonNull TypedArray
obtainStyledAttributes(
    @Nullable AttributeSet p0,
    @NonNull int[] p1,
    int p2,
    int p3
)
void
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent p0,
    @NonNull String[] p1
)
From android.content.ContextWrapper
boolean
bindIsolatedService(
    @NonNull Intent p0,
    int p1,
    @NonNull String p2,
    @NonNull Executor p3,
    @NonNull ServiceConnection p4
)
boolean
boolean
boolean
boolean
bindService(
    @NonNull Intent p0,
    int p1,
    @NonNull Executor p2,
    @NonNull ServiceConnection p3
)
boolean
boolean
bindServiceAsUser(
    @NonNull Intent p0,
    @NonNull ServiceConnection p1,
    int p2,
    @NonNull UserHandle p3
)
int
int
@NonNull int[]
int
int
@NonNull int[]
int
checkContentUriPermissionFull(@NonNull Uri p0, int p1, int p2, int p3)
int
checkPermission(@NonNull String p0, int p1, int p2)
int
int
checkUriPermission(@NonNull Uri p0, int p1, int p2, int p3)
int
checkUriPermission(
    @Nullable Uri p0,
    @Nullable String p1,
    @Nullable String p2,
    int p3,
    int p4,
    int p5
)
@NonNull int[]
checkUriPermissions(@NonNull List<@NonNull Uri> p0, int p1, int p2, int p3)
void

This method is deprecated. Deprecated in Java

@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull String[]
boolean
boolean
boolean
void
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri p0,
    int p1,
    @NonNull String p2
)
void
void
void
enforcePermission(@NonNull String p0, int p1, int p2, @Nullable String p3)
void
enforceUriPermission(
    @NonNull Uri p0,
    int p1,
    int p2,
    int p3,
    @NonNull String p4
)
void
enforceUriPermission(
    @Nullable Uri p0,
    @Nullable String p1,
    @Nullable String p2,
    int p3,
    int p4,
    int p5,
    @Nullable String p6
)
@NonNull String[]
@NonNull Context
@NonNull ApplicationInfo
@NonNull AssetManager
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
@NonNull File
int
@NonNull File
getDir(@NonNull String p0, int p1)
@Nullable Display
@Nullable File
@NonNull File[]
@Nullable File
@NonNull File[]
@NonNull File[]
@NonNull File
@NonNull File
@NonNull Executor
@NonNull Looper
@NonNull File
@NonNull File
@NonNull File[]
@NonNull String
@NonNull String
@NonNull PackageManager
@NonNull String
@NonNull String
@Nullable ContextParams
@NonNull Resources
@NonNull SharedPreferences
@NonNull Object
String
@NonNull Resources.Theme
@NonNull Drawable

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

void
boolean
boolean
boolean
boolean
boolean
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String p0, int p1)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String p0,
    int p1,
    @NonNull SQLiteDatabase.CursorFactory p2
)
@NonNull SQLiteDatabase
@NonNull Drawable

This method is deprecated. Deprecated in Java

void
void
Intent
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    int p2
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    @Nullable String p2,
    @Nullable Handler p3
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    @Nullable String p2,
    @Nullable Handler p3,
    int p4
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
void
void
void
void
void
void
void
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable Bundle p2
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable BroadcastReceiver p2,
    @Nullable Handler p3,
    int p4,
    @Nullable String p5,
    @Nullable Bundle p6
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable Bundle p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable String p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    int p1,
    @Nullable String p2,
    @Nullable String p3,
    @Nullable BroadcastReceiver p4,
    @Nullable Handler p5,
    @Nullable String p6,
    @Nullable Bundle p7,
    @Nullable Bundle p8
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent p0,
    @NonNull UserHandle p1,
    @Nullable String p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable BroadcastReceiver p1,
    @Nullable Handler p2,
    int p3,
    @Nullable String p4,
    @Nullable Bundle p5
)

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent p0,
    @NonNull UserHandle p1,
    @Nullable BroadcastReceiver p2,
    @Nullable Handler p3,
    int p4,
    @Nullable String p5,
    @Nullable Bundle p6
)

This method is deprecated. Deprecated in Java

void
setTheme(int p0)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
startActivities(@NonNull Intent[] p0)
void
startActivities(@NonNull Intent[] p0, @Nullable Bundle p1)
void
void
@Nullable ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName p0,
    @Nullable String p1,
    @Nullable Bundle p2
)
void
startIntentSender(
    @NonNull IntentSender p0,
    @Nullable Intent p1,
    int p2,
    int p3,
    int p4
)
void
startIntentSender(
    @NonNull IntentSender p0,
    @Nullable Intent p1,
    int p2,
    int p3,
    int p4,
    @Nullable Bundle p5
)
@Nullable ComponentName
boolean
void
void
void
void
void
updateServiceGroup(@NonNull ServiceConnection p0, int p1, int p2)
From android.app.Service
void
void
dump(
    @NonNull FileDescriptor p0,
    @NonNull PrintWriter p1,
    @NonNull String[] p2
)
final @NonNull Application
final int
void
void

This method is deprecated.

void
void
onStart(@NonNull Intent p0, int p1)

This method is deprecated. Deprecated in Java

int
onStartCommand(@NonNull Intent p0, int p1, int p2)
void
void
onTimeout(int p0)
void
onTimeout(int p0, int p1)
void
onTrimMemory(int p0)
boolean
final void
final void
startForeground(int p0, @NonNull Notification p1, int p2)
final void
stopForeground(boolean p0)

This method is deprecated. Deprecated in Java

final void
final void
final void
stopSelf(int p0)
final boolean
From androidx.wear.tiles.TileService
@Nullable IBinder
@NonNull ListenableFuture<@NonNull Void>

Called when the system sends a batch of Tile interaction events that happened since the last time this method was called.

@NonNull ListenableFuture<@NonNull ResourceBuilders.Resources>

This method is deprecated.

Use onTileResourcesRequest instead.

void

Called when a tile provided by this Tile Provider is added to the carousel.

void

Called when a tile provided by this Tile Provider is removed from the carousel.

Public constructors

Material3TileService

Added in 1.6.0-alpha04
public Material3TileService(
    boolean allowDynamicTheme,
    @NonNull ColorScheme defaultColorScheme,
    CoroutineScope serviceScope
)
Parameters
boolean allowDynamicTheme

if dynamic colors theme should be used on Material3 components, meaning that colors will follow the system theme if enabled on the device. If not overridden, defaults to using the system theme.

@NonNull ColorScheme defaultColorScheme

the default static color theme to be used, when allowDynamicTheme is false, or when dynamic theming is disabled by the system or user. If not overridden, defaults to default theme.

CoroutineScope serviceScope

the scope to be used for tileResponse call, otherwise the scope running on a main thread will be used.

Public methods

onCreate

@CallSuper
public void onCreate()

onDestroy

@CallSuper
public void onDestroy()

Protected methods

tileResponse

protected abstract @NonNull TileBuilders.Tile tileResponse(
    @NonNull MaterialScope receiver,
    @NonNull RequestBuilders.TileRequest requestParams
)

Called when the system is requesting a new timeline from this Tile Provider.

Resulting Tile can be created within the receiver MaterialScope which is used by all ProtoLayout Material3 components and layout to support opinionated defaults and to provide the global information for styling Material3 components. Additionally, the MaterialScope contains ProtoLayoutScope for automatic resource registration for any Image elements used within a Tile.

Note that, all resources used within the tile layout should be directly embedded as ResourceBuilders.ImageResource in layout using the corresponding API (such as androidx.wear.protolayout.layout.basicImage or Material3 counterparts (for example androidx.wear.protolayout.material3.backgroundImage).

This runs a suspending function on the Main thread, unless serviceScope is overridden.

Parameters
@NonNull RequestBuilders.TileRequest requestParams

Parameters about the request. See TileRequest for more info. Note that handle to some of them exists in the MaterialScope (for example deviceConfiguration for DeviceParameters.