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.ComponentCallbacks
From android.content.ComponentCallbacks2
open Unit
onTrimMemory(level: Int)
From android.content.Context
open Boolean
bindIsolatedService(
    service: Intent,
    flags: Context.BindServiceFlags,
    instanceName: String,
    executor: Executor,
    conn: ServiceConnection
)
open Boolean
bindIsolatedService(
    service: Intent,
    flags: Int,
    instanceName: String,
    executor: Executor,
    conn: ServiceConnection
)
open Boolean
bindService(
    service: Intent,
    conn: ServiceConnection,
    flags: Context.BindServiceFlags
)
open Boolean
bindService(service: Intent, conn: ServiceConnection, flags: Int)
open Boolean
bindService(
    service: Intent,
    flags: Context.BindServiceFlags,
    executor: Executor,
    conn: ServiceConnection
)
open Boolean
bindService(
    service: Intent,
    flags: Int,
    executor: Executor,
    conn: ServiceConnection
)
open Boolean
bindServiceAsUser(
    service: Intent,
    conn: ServiceConnection,
    flags: Context.BindServiceFlags,
    user: UserHandle
)
open Boolean
bindServiceAsUser(
    service: Intent,
    conn: ServiceConnection,
    flags: Int,
    user: UserHandle
)
open Int
open Int
open IntArray
open Int
open Int
checkCallingUriPermission(uri: Uri, modeFlags: Int)
open IntArray
open Int
checkContentUriPermissionFull(uri: Uri, pid: Int, uid: Int, modeFlags: Int)
open Int
checkPermission(permission: String, pid: Int, uid: Int)
open Int
open Int
checkUriPermission(uri: Uri, pid: Int, uid: Int, modeFlags: Int)
open Int
checkUriPermission(
    uri: Uri?,
    readPermission: String?,
    writePermission: String?,
    pid: Int,
    uid: Int,
    modeFlags: Int
)
open IntArray
checkUriPermissions(
    uris: MutableList<Uri>,
    pid: Int,
    uid: Int,
    modeFlags: Int
)
open Unit

This function is deprecated. Deprecated in Java

open Context
createAttributionContext(attributionTag: String?)
open Context
createConfigurationContext(overrideConfiguration: Configuration)
open Context
createContext(contextParams: ContextParams)
open Context
open Context
open Context
open Context
open Context
createPackageContext(packageName: String, flags: Int)
open Context
createWindowContext(type: Int, options: Bundle?)
open Context
createWindowContext(display: Display, type: Int, options: Bundle?)
open Array<String>
open Boolean
open Boolean
open Boolean
open Unit
enforceCallingOrSelfPermission(permission: String, message: String?)
open Unit
enforceCallingOrSelfUriPermission(
    uri: Uri,
    modeFlags: Int,
    message: String
)
open Unit
enforceCallingPermission(permission: String, message: String?)
open Unit
enforceCallingUriPermission(uri: Uri, modeFlags: Int, message: String)
open Unit
enforcePermission(permission: String, pid: Int, uid: Int, message: String?)
open Unit
enforceUriPermission(
    uri: Uri,
    pid: Int,
    uid: Int,
    modeFlags: Int,
    message: String
)
open Unit
enforceUriPermission(
    uri: Uri?,
    readPermission: String?,
    writePermission: String?,
    pid: Int,
    uid: Int,
    modeFlags: Int,
    message: String?
)
open Array<String>
Int
ColorStateList
open File
open File
getDir(name: String, mode: Int)
Drawable?
open File?
open Array<File>
open File
open SharedPreferences
String
getString(resId: Int)
String
getString(resId: Int, vararg formatArgs: Any)
open Any
T
<T : Any> getSystemService(serviceClass: Class<T>)
open String?
getSystemServiceName(serviceClass: Class<*>)
CharSequence
getText(resId: Int)
open Unit
grantUriPermission(toPackage: String, uri: Uri, modeFlags: Int)
open Boolean
moveDatabaseFrom(sourceContext: Context, name: String)
open Boolean
moveSharedPreferencesFrom(sourceContext: Context, name: String)
TypedArray
TypedArray
TypedArray
TypedArray
obtainStyledAttributes(
    set: AttributeSet?,
    attrs: IntArray,
    defStyleAttr: Int,
    defStyleRes: Int
)
open FileInputStream
open FileOutputStream
openFileOutput(name: String, mode: Int)
open SQLiteDatabase
openOrCreateDatabase(
    name: String,
    mode: Int,
    factory: SQLiteDatabase.CursorFactory
)
open SQLiteDatabase
openOrCreateDatabase(
    name: String,
    mode: Int,
    factory: SQLiteDatabase.CursorFactory,
    errorHandler: DatabaseErrorHandler?
)
open Drawable

This function is deprecated. Deprecated in Java

open Unit
open Unit
open Intent?
open Intent?
registerReceiver(
    receiver: BroadcastReceiver?,
    filter: IntentFilter,
    flags: Int
)
open Intent?
registerReceiver(
    receiver: BroadcastReceiver?,
    filter: IntentFilter,
    broadcastPermission: String?,
    scheduler: Handler?
)
open Intent?
registerReceiver(
    receiver: BroadcastReceiver?,
    filter: IntentFilter,
    broadcastPermission: String?,
    scheduler: Handler?,
    flags: 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(uri: Uri, modeFlags: Int)
open Unit
revokeUriPermission(targetPackage: String, uri: Uri, modeFlags: Int)
open Unit
open Unit
sendBroadcast(intent: Intent, receiverPermission: String?)
open Unit
sendBroadcast(intent: Intent, receiverPermission: String?, options: Bundle?)
open Unit
open Unit
sendBroadcastAsUser(
    intent: Intent,
    user: UserHandle,
    receiverPermission: String?
)
open Unit
sendBroadcastWithMultiplePermissions(
    intent: Intent,
    receiverPermissions: Array<String>
)
open Unit
sendOrderedBroadcast(intent: Intent, receiverPermission: String?)
open Unit
sendOrderedBroadcast(
    intent: Intent,
    receiverPermission: String?,
    options: Bundle?
)
open Unit
sendOrderedBroadcast(
    intent: Intent,
    receiverPermission: String?,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)
open Unit
sendOrderedBroadcast(
    intent: Intent,
    receiverPermission: String?,
    options: Bundle?,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)
open Unit
sendOrderedBroadcast(
    intent: Intent,
    receiverPermission: String?,
    receiverAppOp: String?,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)
open Unit
sendOrderedBroadcastAsUser(
    intent: Intent,
    user: UserHandle,
    receiverPermission: String?,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)
open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyBroadcast(intent: Intent, options: Bundle?)

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcast(
    intent: Intent,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
sendStickyOrderedBroadcastAsUser(
    intent: Intent,
    user: UserHandle,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialCode: Int,
    initialData: String?,
    initialExtras: Bundle?
)

This function is deprecated. Deprecated in Java

open Unit
setTheme(resid: Int)
open Unit

This function is deprecated. Deprecated in Java

open Unit

This function is deprecated. Deprecated in Java

open Unit
open Unit
startActivities(intents: Array<Intent>, options: Bundle?)
open Unit
open Unit
startActivity(intent: Intent, options: Bundle?)
open ComponentName?
open Boolean
startInstrumentation(
    className: ComponentName,
    profileFile: String?,
    arguments: Bundle?
)
open Unit
startIntentSender(
    intent: IntentSender,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)
open Unit
startIntentSender(
    intent: IntentSender,
    fillInIntent: Intent?,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle?
)
open ComponentName?
startService(service: Intent)
open Boolean
open Unit
open Unit
open Unit
open Unit
open Unit
updateServiceGroup(conn: ServiceConnection, group: Int, importance: Int)
From android.content.ContextWrapper
open Unit
open Unit
sendOrderedBroadcast(
    intent: Intent,
    initialCode: Int,
    receiverPermission: String?,
    receiverAppOp: String?,
    resultReceiver: BroadcastReceiver?,
    scheduler: Handler?,
    initialData: String?,
    initialExtras: Bundle?,
    options: Bundle?
)
From android.app.Service
open Unit
dump(fd: FileDescriptor, writer: PrintWriter, args: Array<String>)
open IBinder?
onBind(intent: Intent)
open Unit
onRebind(intent: Intent)
open Unit
onStart(intent: Intent, startId: Int)

This function is deprecated. Deprecated in Java

open Int
onStartCommand(intent: Intent, flags: Int, startId: Int)
open Unit
onTaskRemoved(rootIntent: Intent)
open Unit
onTimeout(startId: Int)
open Unit
onTimeout(startId: Int, fgsType: Int)
open Boolean
onUnbind(intent: Intent)
Unit
startForeground(id: Int, notification: Notification)
Unit
startForeground(
    id: Int,
    notification: Notification,
    foregroundServiceType: Int
)
Unit
stopForeground(notificationBehavior: Int)
Unit
stopForeground(removeNotification: Boolean)

This function is deprecated. Deprecated in Java

Unit
Unit
stopSelf(startId: Int)
Boolean
stopSelfResult(startId: Int)
From androidx.wear.tiles.TileService
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-beta01
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.