Creating Tiles for Wear OS

Jun 8 2021 · Kotlin 1.5, Android 8, Android Studio 4.2

Part 1: Creating Tiles for Wear OS

02. Set Up the Project

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Learn About Wear OS Tiles Next episode: 03. Create a Basic Tile

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Demo $[==]

To set up the project, first, open the app build.gradle and add the following dependencies:

implementation 'androidx.wear:wear:1.1.0'
implementation "androidx.wear.tiles:tiles:1.0.0-alpha05"
debugImplementation "androidx.wear.tiles:tiles-renderer:1.0.0-alpha05"
class WaterService : TileProviderService() {

  private val ioScope = CoroutineScope(Dispatchers.IO)

  override fun onDestroy() {
    super.onDestroy()
    ioScope.cancel()
  }

}
override fun onTileRequest(requestParams: RequestReaders.TileRequest): ListenableFuture<TileBuilders.Tile> {
  return ioScope.future {

    TileBuilders.Tile.builder()
      .setResourcesVersion("1")
      .build()

  }
}

override fun onResourcesRequest(requestParams: RequestReaders.ResourcesRequest): ListenableFuture<ResourceBuilders.Resources> {
  return ioScope.future {
    ResourceBuilders.Resources.builder()
      .setVersion("1")
      .build()
  }
}
android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER"
<intent-filter>
  <action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER" />
</intent-filter>
class DebugActivity : ComponentActivity() {

  private lateinit var tileClient: TileClient

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_debug)

    val rootLayout = findViewById<FrameLayout>(R.id.container)

    tileClient = TileClient(
      context = this,
      component = ComponentName(this, WaterService::class.java),
      parentView = rootLayout
    )
    tileClient.connect()
  }

  override fun onDestroy() {
    super.onDestroy()
    tileClient.close()
  }

}
<FrameLayout android:id="@+id/container"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>
<uses-feature android:name="android.hardware.type.watch" />