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.ComponentCallbacks
From android.content.ComponentCallbacks2
void
onTrimMemory(int level)
From android.content.Context
boolean
bindIsolatedService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindIsolatedService(
    @NonNull Intent service,
    int flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    int flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags,
    @NonNull UserHandle user
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags,
    @NonNull UserHandle user
)
int
int
@NonNull int[]
checkCallingOrSelfUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int modeFlags
)
int
int
checkCallingUriPermission(@NonNull Uri uri, int modeFlags)
@NonNull int[]
int
checkContentUriPermissionFull(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags
)
int
checkPermission(@NonNull String permission, int pid, int uid)
int
int
checkUriPermission(@NonNull Uri uri, int pid, int uid, int modeFlags)
int
checkUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags
)
@NonNull int[]
checkUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int pid,
    int uid,
    int modeFlags
)
void

This method is deprecated. Deprecated in Java

@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
createDeviceContext(int deviceId)
@NonNull Context
@NonNull Context
@NonNull Context
createPackageContext(@NonNull String packageName, int flags)
@NonNull Context
createWindowContext(int type, @Nullable Bundle options)
@NonNull Context
createWindowContext(
    @NonNull Display display,
    int type,
    @Nullable Bundle options
)
@NonNull String[]
boolean
boolean
boolean
void
enforceCallingOrSelfPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforceCallingPermission(
    @NonNull String permission,
    @Nullable String message
)
void
enforceCallingUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforcePermission(
    @NonNull String permission,
    int pid,
    int uid,
    @Nullable String message
)
void
enforceUriPermission(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags,
    @NonNull String message
)
void
enforceUriPermission(
    @Nullable Uri uri,
    @Nullable String readPermission,
    @Nullable String writePermission,
    int pid,
    int uid,
    int modeFlags,
    @Nullable String message
)
@NonNull String[]
final int
getColor(int id)
final @NonNull ColorStateList
@NonNull File
@NonNull File
getDir(@NonNull String name, int mode)
final @Nullable Drawable
getDrawable(int id)
@Nullable File
@NonNull File[]
@NonNull File
@NonNull SharedPreferences
getSharedPreferences(@NonNull String name, int mode)
final @NonNull String
getString(int resId)
final @NonNull String
getString(int resId, @NonNull Object... formatArgs)
@NonNull Object
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> serviceClass)
String
final @NonNull CharSequence
getText(int resId)
void
grantUriPermission(
    @NonNull String toPackage,
    @NonNull Uri uri,
    int modeFlags
)
boolean
moveDatabaseFrom(@NonNull Context sourceContext, @NonNull String name)
boolean
moveSharedPreferencesFrom(
    @NonNull Context sourceContext,
    @NonNull String name
)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int resid, @NonNull int[] attrs)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(
    @Nullable AttributeSet set,
    @NonNull int[] attrs,
    int defStyleAttr,
    int defStyleRes
)
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String name, int mode)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory
)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory,
    @Nullable DatabaseErrorHandler errorHandler
)
@NonNull Drawable

This method is deprecated. Deprecated in Java

void
void
registerDeviceIdChangeListener(
    @NonNull Executor executor,
    @NonNull IntConsumer listener
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    int flags
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    @Nullable String broadcastPermission,
    @Nullable Handler scheduler,
    int flags
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
void
revokeUriPermission(@NonNull Uri uri, int modeFlags)
void
revokeUriPermission(
    @NonNull String targetPackage,
    @NonNull Uri uri,
    int modeFlags
)
void
void
sendBroadcast(@NonNull Intent intent, @Nullable String receiverPermission)
void
sendBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
void
sendBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    String receiverPermission
)
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent intent,
    @NonNull String[] receiverPermissions
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable Bundle options,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable String receiverPermission,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)
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 intent,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    int initialCode,
    @Nullable String initialData,
    @Nullable Bundle initialExtras
)

This method is deprecated. Deprecated in Java

void
setTheme(int resid)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
startActivities(@NonNull Intent[] intents)
void
startActivities(@NonNull Intent[] intents, @Nullable Bundle options)
void
void
@Nullable ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName className,
    @Nullable String profileFile,
    @Nullable Bundle arguments
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSender(
    @NonNull IntentSender intent,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)
@Nullable ComponentName
boolean
void
void
void
void
void
updateServiceGroup(
    @NonNull ServiceConnection conn,
    int group,
    int importance
)
From android.content.ContextWrapper
void
@NonNull Context
@NonNull ApplicationInfo
@NonNull AssetManager
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
int
@Nullable Display
@Nullable 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 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

boolean
boolean
boolean
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    int initialCode,
    @Nullable String receiverPermission,
    @Nullable String receiverAppOp,
    @Nullable BroadcastReceiver resultReceiver,
    @Nullable Handler scheduler,
    @Nullable String initialData,
    @Nullable Bundle initialExtras,
    @Nullable Bundle options
)
From android.app.Service
void
dump(
    @NonNull FileDescriptor fd,
    @NonNull PrintWriter writer,
    @NonNull String[] args
)
final @NonNull Application
final int
@Nullable IBinder
void
void
onStart(@NonNull Intent intent, int startId)

This method is deprecated. Deprecated in Java

int
onStartCommand(@NonNull Intent intent, int flags, int startId)
void
void
onTimeout(int startId)
void
onTimeout(int startId, int fgsType)
boolean
final void
startForeground(int id, @NonNull Notification notification)
final void
startForeground(
    int id,
    @NonNull Notification notification,
    int foregroundServiceType
)
final void
stopForeground(int notificationBehavior)
final void
stopForeground(boolean removeNotification)

This method is deprecated. Deprecated in Java

final void
final void
stopSelf(int startId)
final boolean
stopSelfResult(int startId)
From androidx.wear.tiles.TileService
@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-beta01
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.