Communicating between Wear OS and Android device using the OpWear module and a sample of displaying real-time camera on the watch and sending commands to the mobile by Wear OS.

Overview

OpWear-Cam

Communicating between Wear OS and Android device using the OpWear module and a sample of displaying real-time camera on the watch and sending commands to the mobile by Wear OS.

Usage

class MainActivity : AppCompatActivity(),
    OpWear.OnConnectionChangedListener,
    MessageClient.OnMessageReceivedListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        // ***
        
        OpWear.install(this)
        
        // ONLY OBSERVER SHOULD CALL THIS
        lifecycleScope.launch { OpWear.connect() }
    }

    override fun onConnectionChange(status: OpWear.ConnectionStatus) {
        println(status.name)

        if (status == OpWear.ConnectionStatus.CONNECTED) {
            lifecycleScope.launch {
                OpWear.sendMessage(
                    "Hello",
                    "Hello ${OpWear.connectedNodeDisplayName}!".toByteArray()
                )
            }
        }
    }

    override fun onMessageReceived(msg: MessageEvent) {
        println("MESSAGE RECEIVED:")
        println(msg.path)
        println(String(msg.data))
    }
}

We consider one device as observer and another as observable. In sample, mobile is the observer. The only difference is that the Observer must call ‍OpWear.connect(), while the Observable can accept or reject the Observer's request.

By default every request is accepted by observable. You can implement OpWear.OnAcknowledgeListener to manage requests.

OpWear.acknowledgeListener = OpWear.OnAcknowledgeListener { nodeId, displayName ->
    println("$displayName:$nodeId WANTS TO CONNECT")
    true
}

By calling OpWear.install(context), If the context is an instance of LifecycleOwner, everything will be handled, but otherwise you have to call

OpWear.attachToLifecycle(owner)

OR

override fun onResume() {
    super.onResume()
    OpWear.register()
}

override fun onPause() {
    super.onPause()
    OpWear.unregister()
}

AutoValidation

Auto validation will make sure that connection is alive.

  • RESPONSE: Must receive a message within the specified time. Useful for observable real-time connections.
  • ACKNOWLEDGE: Sends acknowledgment request at the specified time interval.
OpWear.autoValidationStrategy = OpWear.AutoValidationStrategy.NONE
OpWear.autoValidationStrategy = OpWear.AutoValidationStrategy.RESPONSE
OpWear.autoValidationStrategy = OpWear.AutoValidationStrategy.ACKNOWLEDGE

License

Copyright 2022 Amir Hossein Aghajari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

LCoders | AmirHosseinAghajari
Amir Hossein Aghajari • EmailGitHub
You might also like...
Learn about your favorite Marvel characters, super heroes, villains and watch videos from official Marvel youtube channel.
Learn about your favorite Marvel characters, super heroes, villains and watch videos from official Marvel youtube channel.

Marvel Super Heroes Android App 📱 Learn about your favorite Marvel characters, super heroes, villains and watch videos from official Marvel youtube c

This android app fetches the data from the USGS API in real time to display a list of earthquakes.

This android app fetches the data from the USGS API in real time to display a list of earthquakes. On clicking an earthquake it opens a browser window with the complete information of the earthquake along with the location on a map.

Real time gps location based alarming system tracking the road accident and providing medical assitance plus concern from near by police station.
Real time gps location based alarming system tracking the road accident and providing medical assitance plus concern from near by police station.

Real time gps location based alarming system tracking the road accident and providing medical assitance plus concern from near by police station.

Ipify allows users to get current public IP address for connected network in real-time
Ipify allows users to get current public IP address for connected network in real-time

Ipify-Android Ipify allows you to get current public IP address when connected to internet in real-time Add Dependency Use Gradle: Step 1: Add it in y

A real time notification App which reminds its user with daily schedules

On Time Pro ⌚ A real time notification App which reminds its user with daily schedules, time-table ⌛ , due assignments 📜 , regular classes with just

Program, created to make popular adb and fastboot commands easier to use
Program, created to make popular adb and fastboot commands easier to use

Android Tool What is it? Android Tool is a powerful and beautiful program, created to make popular adb and fastboot commands easier to use. A dark the

Andorid app which provides a bunch of useful Linux commands.
Andorid app which provides a bunch of useful Linux commands.

Linux Command Library for Android The app currently has 3203 manual pages, 1351 one-line scripts and a bunch of general terminal tips. It works 100% o

This component allows you to interact with remote machine via SSH. You can execute commands or run scripts located on that machine

th2 act ssh (1.2.0) Overview Provides user with the ability to execute specified scripts or commands with the parameter he needs Custom resources for

Photon Framework provides cool way to Discord Slash Commands 👩‍💻 🚧

Photon Framework provides cool way to Discord Slash Commands 👩‍💻 🚧

Owner
AmirHosseinAghajari
AmirHosseinAghajari
Sync DND state between Android phone and watch

DNDSync This App was developed to enable Do Not Disturb (DND) synchronization between my Pixel phone and the Galaxy Watch 4 since this option was only

rhaeus 57 Jan 5, 2023
Sending komq's latest YouTube & Twitch notifications via Twitter.

Komwitter Twitch & YouTube Notification Twitter Bot for komq. Used Libraries: Twitter4J Twitch4J Kotlinx.serialization and some other dependency libra

BaeHyeonWoo 4 Feb 10, 2022
Market Watch is Android app using Alpha Vantage API. Live stock and market data.

Donate If you like this app please donate Bitcoin: bc1qwqqpuy54qfja7h5dzpd9swgrnkql02t8cacn62 About this app Market Watch allows to watch and track s

Krzysztof Kobiałka 1 May 22, 2022
WatchFaceAlphaKotlin - Demonstrates watch faces using the new androidX alpha libraries (Kotlin)

Alpha WatchFace Sample (Kotlin) Demonstrates watch faces using the new androidX

Bastiaan Quast 0 Jan 4, 2022
An MVP Dribbble client for Android Mobile, Tablet, Wear and TV.

Bourbon ![Sidebar] (https://img.shields.io/badge/Sidebar-06%2F05%2F2016-orange.svg) Bourbon is a simple Dribbble client built for Android Mobile, Wear

Joe Birch 1.1k Dec 12, 2022
Abel Suviri 6 Dec 16, 2022
SimpleCloud-haste-module - SimpleCloud module for uploading the logs of your services to hastebin

SimpleCloud Haste Module A SimpleCloud Module for uploading the current logs of

NeverStopGaming.net 5 Mar 6, 2022
An Android app to watch anime on your phone without ads.

Anime X Stream An Android app to watch anime on your phone without ads. WARNING: THIS IS A BETA VERSION of application, THEREFORE YOU MAY ENCOUNTER BU

Mukul Banga 2.2k Jan 4, 2023
Android app for watch replays at wasd.tv with autoscroll chat

WasdReplayAndroid Приложение для просмотра записей на васде с чатом на андроиде. https://github.com/Kirimatt/WasdReplayAndroid/blob/master/app/build/i

Azamat 25 Nov 12, 2022
Android TicWatch E-3 API 28 in Kotlin Animated Watch

AndroidTicWatchE3 -WEAR OS API 28 in Kotlin Android Studio- [CODE SNIPPETS] TicWatch E-3 Virtual Star Pet Features: Daily Background Change Holiday Mo

Sarah Bass 3 Aug 16, 2022