Introduction
Getting started with WearOs in compose is going to be very easy and a nutshell. If you have already used Jetpack Compose to develop apps, you can start creating code for Wear OS with ease.
Compose knowledge can offer you an advantage in this situation, but you don't have to be an all-arounder to start.

Here, we'll start by comprehending the project's overall needs before learning about Wear OS's fundamental parts and features. With the help of this article, you can easily create a simple app for Wear OS.
Project Set Up
Create a new Project in the Android Studio by Selecting the Wear OS in the sidebar and then choosing the Empty Wear App like the below image.

Explore the Project
Let's see how the project is organized by android studio regarding Wear OS.
main > theme/
This folder contains the Color, Type, and Theme files used by Compose for the theme.
res > strings/
This folder contains two strings.xml files, one for round and the second for square devices. This string will compile according to the device specification.
build.gradle
It contains a basic app configuration. It includes the dependencies necessary to create a Composable Wear OS App.
main > AndroidManifest.xml
It includes the elements necessary to create a Wear OS application. This is the same as a non-Compose app and similar to a mobile app, so we won't review this.
main > MainActivity.kt
It contains code for creating an app with Compose. It also contains the top-level composables (like the Scaffold) for our app.

Dependencies
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'com.google.android.gms:play-services-wearable:18.0.0'
implementation platform('androidx.compose:compose-bom:2023.03.00')
//compose for wear os
implementation 'androidx.wear.compose:compose-material:1.0.0'
implementation 'androidx.wear.compose:compose-foundation:1.0.0'
//General compose
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-tooling-preview'
// Testing
androidTestImplementation platform('androidx.compose:compose-bom:2023.03.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
//added
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.wear.compose:compose-material:$wear_compose_version"
}
Starting with Entry Point

Open MainActivity in the project. This is a pretty simple class that extends ComponentActivity and uses setContent { WearApp() } to create the UI. This ought to look familiar to you based on what you've already learned about Compose. The UI is currently being put up.
Locate the WearApp() composable function by scrolling down. You should notice a lot of TODOs strewn throughout the code before we discuss the actual function. Each of these denotes a step in this article. For the time being, ignore them.
It should resemble the following.
WearOsExampleTheme {
val listState = rememberLazyListState()
val contentModifier = Modifier
.fillMaxWidth()
.padding(bottom = 8.dp)
val iconModifier = Modifier
.size(24.dp)
.wrapContentSize(align = Alignment.Center)
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(
top = 32.dp,
start = 8.dp,
end = 8.dp,
bottom = 32.dp
),
verticalArrangement = Arrangement.Center,
state = listState
) {
// TO-DO: PlayButton
item { ButtonExample(contentModifier, iconModifier) }
// TO-DO: Text
item { TextExample(contentModifier) }
// TO-DO: Card
item { CardExample(contentModifier, iconModifier) }
// TO-DO: Chip
item { ChipExample(contentModifier, iconModifier) }
// TO-DO: Toggle Chip
item { ToggleChipExample(contentModifier) }
}
}
For the Wear composable, we have created some Modifiers so we don't have to define them every time. The content is primarily being centered, and some padding added. Then we created a lazy column which is used to show a list of items in a verticle way.
Now we are going to cover some of the components (which are in todo). So without further waiting, let's implement them!
1. Button Component
In the Main Activity, create a new composable function with ButtonExample or paste the following code.
@Composable
fun ButtonExample(
modifier: Modifier = Modifier, iconModifier: Modifier = Modifier
) {
Row(
modifier = modifier, horizontalArrangement = Arrangement.Center
) {
// Button
Button(
modifier = Modifier.size(ButtonDefaults.LargeButtonSize),
onClick = { /* ... */ },
) {
Icon(
imageVector = Icons.Rounded.PlayArrow,
contentDescription = "Play Music",
modifier = iconModifier
)
}
}
}
This will generate a button in the centre which will look like below

Passing the modifier into the row makes it in the centre. While the button uses the large button size and optimizes the size for wear os and now we set the icon and click event to empty lambda.
2. Text composable
We define only the text composable here. its modifier will be as we define previously, the text will be centre aligned, setting a colour to primary and finally setting the string.
@Composable
fun TextExample(modifier: Modifier = Modifier) {
Text(
modifier = modifier,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = "Play Music on "+stringResource(R.string.device_shape)
)
}










Gaurav KumarPosted Aug 11, 2023, 6:04 AM
Nice article Ravikant Sahu Thanks for sharing!! btw can we create custom position slider indicator.
Uday DodiyaPosted Aug 11, 2023, 5:57 AM
Good Content..
Abhishek TiwariPosted Aug 10, 2023, 6:10 AM
Nice Article Ravi.