Material3TileService


abstract class Material3TileService : 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(
    allowDynamicTheme: Boolean,
    defaultColorScheme: ColorScheme,
    serviceScope: CoroutineScope?
)

Public functions

open Unit
open Unit

Protected functions

abstract suspend TileBuilders.Tile

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

Inherited functions

From android.content.Context
From android.content.ContextWrapper
open Boolean
bindIsolatedService(
    p0: Intent,
    p1: Int,
    p2: String,
    p3: Executor,
    p4: ServiceConnection
)
open Boolean
bindService(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags
)
open Boolean
open Boolean
bindService(
    p0: Intent,
    p1: Context.BindServiceFlags,
    p2: Executor,
    p3: ServiceConnection
)
open Boolean
bindService(p0: Intent, p1: Int, p2: Executor, p3: ServiceConnection)
open Boolean
bindServiceAsUser(
    p0: Intent,
    p1: ServiceConnection,
    p2: Context.BindServiceFlags,
    p3: UserHandle
)
open Boolean
open Int
open Int
open IntArray
open Int
open Int
open IntArray
open Int
checkContentUriPermissionFull(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkPermission(p0: String, p1: Int, p2: Int)
open Int
open Int
checkUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int)
open Int
checkUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int)
open IntArray
checkUriPermissions(p0: MutableList<Uri>, p1: Int, p2: Int, p3: Int)
open Unit

This function is deprecated. Deprecated in Java

open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
open Context
createWindowContext(p0: Display, p1: Int, p2: Bundle?)
open Array<String>
open Boolean
open Boolean
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
enforcePermission(p0: String, p1: Int, p2: Int, p3: String?)
open Unit
enforceUriPermission(p0: Uri, p1: Int, p2: Int, p3: Int, p4: String)
open Unit
enforceUriPermission(
    p0: Uri?,
    p1: String?,
    p2: String?,
    p3: Int,
    p4: Int,
    p5: Int,
    p6: String?
)
open Array<String>
open Context
open ApplicationInfo
open AssetManager
open AttributionSource
open String?
open Context
open File
open ClassLoader
open File
open ContentResolver
open File
open File
open Int
open File
getDir(p0: String, p1: Int)
open Display?
open File?
open Array<File>
open File?
open Array<File>
open Array<File>
open File
open File
open Executor
open Looper
open File
open File
open Array<File>
open String
open String
open PackageManager
open String
open String
open ContextParams?
open Resources
open SharedPreferences
open Any
open String?
open Resources.Theme
open Drawable

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Int

This function is deprecated. Deprecated in Java

open Unit
grantUriPermission(p0: String, p1: Uri, p2: Int)
open Boolean
open Boolean
open Boolean
open Boolean
open Boolean
open FileInputStream
open FileOutputStream
open SQLiteDatabase
open SQLiteDatabase
openOrCreateDatabase(
    p0: String,
    p1: Int,
    p2: SQLiteDatabase.CursorFactory,
    p3: DatabaseErrorHandler?
)
open Drawable

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Intent?
open Intent?
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?
)
open Intent?
registerReceiver(
    p0: BroadcastReceiver?,
    p1: IntentFilter,
    p2: String?,
    p3: Handler?,
    p4: Int
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
revokeUriPermission(p0: String, p1: Uri, p2: Int)
open Unit
open Unit
open Unit
sendBroadcast(p0: Intent, p1: String?, p2: Bundle?)
open Unit
open Unit
open Unit
open Unit
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: Bundle?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: String?,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit
sendOrderedBroadcast(
    p0: Intent,
    p1: Int,
    p2: String?,
    p3: String?,
    p4: BroadcastReceiver?,
    p5: Handler?,
    p6: String?,
    p7: Bundle?,
    p8: Bundle?
)
open Unit
sendOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: String?,
    p3: BroadcastReceiver?,
    p4: Handler?,
    p5: Int,
    p6: String?,
    p7: Bundle?
)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcast(
    p0: Intent,
    p1: BroadcastReceiver?,
    p2: Handler?,
    p3: Int,
    p4: String?,
    p5: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcastAsUser(
    p0: Intent,
    p1: UserHandle,
    p2: BroadcastReceiver?,
    p3: Handler?,
    p4: Int,
    p5: String?,
    p6: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Unit
open Unit
open ComponentName?
open Boolean
open Unit
startIntentSender(p0: IntentSender, p1: Intent?, p2: Int, p3: Int, p4: Int)
open Unit
startIntentSender(
    p0: IntentSender,
    p1: Intent?,
    p2: Int,
    p3: Int,
    p4: Int,
    p5: Bundle?
)
open ComponentName?
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
From android.app.Service
open Unit
open Unit
Application
Int
open Unit
open Unit

This function is deprecated.

open Unit
open Unit
onStart(p0: Intent, p1: Int)

This function is deprecated. Deprecated in Java

open Int
onStartCommand(p0: Intent, p1: Int, p2: Int)
open Unit
open Unit
open Unit
onTimeout(p0: Int, p1: Int)
open Unit
open Boolean
Unit
Unit
startForeground(p0: Int, p1: Notification, p2: Int)
Unit

This function is deprecated. Deprecated in Java

Unit
Unit
Unit
Boolean
From androidx.wear.tiles.TileService
open IBinder?
onBind(intent: Intent)
open ListenableFuture<Void>

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

open ListenableFuture<ResourceBuilders.Resources>

This function is deprecated.

Use onTileResourcesRequest instead.

open Unit

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

open Unit

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

Public constructors

Material3TileService

Added in 1.6.0-alpha04
Material3TileService(
    allowDynamicTheme: Boolean = true,
    defaultColorScheme: ColorScheme = ColorScheme(),
    serviceScope: CoroutineScope? = null
)
Parameters
allowDynamicTheme: Boolean = true

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.

defaultColorScheme: ColorScheme = ColorScheme()

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.

serviceScope: CoroutineScope? = null

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

Public functions

onCreate

@CallSuper
open fun onCreate(): Unit

onDestroy

@CallSuper
open fun onDestroy(): Unit

Protected functions

tileResponse

protected abstract suspend fun MaterialScope.tileResponse(requestParams: RequestBuilders.TileRequest): TileBuilders.Tile

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
requestParams: RequestBuilders.TileRequest

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.