Android Wear OS

Wear OS is a version of the Google Android operating system. It is designed for smartwatches and other wearable devices. Wear OS supports Bluetooth,3G, Wi-Fi, and LTE connectivity and it works on the application range.

The smartwatch interface includes round, square, and rectangular. Many partners include LG, HTC, etc.


Step 1: Create a wear app on Android Studio.


Step 2: Create a project or you can use an already created project. You can use any language, Java or Kotlin.


Step 3: Right-click on your project packager name -> click on new -> Wear -> Empty wear app.


Step 4: Open the below dialog and click to finish.


Step 5: Automatically created view is MainActivity.kt file.

import android.os.Bundle

import androidx.activity.ComponentActivity

import androidx.activity.compose.setContent

import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen

import androidx.compose.foundation.background

import androidx.compose.foundation.layout.Box

import androidx.compose.foundation.layout.fillMaxSize

import androidx.compose.foundation.layout.fillMaxWidth

import androidx.compose.runtime.Composable

import androidx.compose.ui.Alignment

import androidx.compose.ui.Modifier

import androidx.compose.ui.res.stringResource

import androidx.compose.ui.text.style.TextAlign

import androidx.compose.ui.tooling.preview.Devices

import androidx.compose.ui.tooling.preview.Preview

import androidx.wear.compose.material.MaterialTheme

import androidx.wear.compose.material.Text

import androidx.wear.compose.material.TimeText

import com.velodate.myapplication.R

import com.velodate.presentation.theme.MyApplicationTheme

 

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

installSplashScreen()

 

super.onCreate(savedInstanceState)

 

setTheme(android.R.style.Theme_DeviceDefault)

setContent {

WearApp("Android")}}}

 

//wear app default method

@Composable

fun WearApp(greetingName: String) {

MyApplicationTheme {

Box(

modifier = Modifier

.fillMaxSize()

.background(MaterialTheme.colors.background),

contentAlignment = Alignment.Center

) {

TimeText()

Greeting2(greetingName = greetingName)}}}

 

@Composable

fun Greeting2(greetingName: String) {

Text(

modifier = Modifier.fillMaxWidth(),

textAlign = TextAlign.Center,

color = MaterialTheme.colors.primary,

text = stringResource(R.string.hello_world, greetingName))

}

@Preview(device = Devices.WEAR_OS_SMALL_ROUND, showSystemUi = true)

@Composable

fun DefaultPreview2() {

WearApp("Preview Android")}

Step 6: The Output.




Happy Coding!

365Bloggy May 9, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive