Skip to content

Comments

Fixes sending messages from the Android app to the Garmin watches#3

Open
pdeubel wants to merge 1 commit intogarmin:mainfrom
pdeubel:fix-send-msg-to-watch
Open

Fixes sending messages from the Android app to the Garmin watches#3
pdeubel wants to merge 1 commit intogarmin:mainfrom
pdeubel:fix-send-msg-to-watch

Conversation

@pdeubel
Copy link

@pdeubel pdeubel commented Sep 17, 2022

As described in #2, sending messages from the Android app to the Garmin watch (in my case the Connect IQ simulator) did not work and resulted in a android.os.NetworkOnMainThreadException. This error is caused when sending messages in the main/UI thread. I fixed it by moving the message sending to a coroutine.

Additional changes:

  • Kotlin coroutines require a scope, therefore I included the androidx lifecycle dependency, and switched the DeviceActivity to be an AppCompatActivity (otherwise the lifecycle scope did not work)
  • This also required changing the themes to be AppCompat themes (the design should be equal to the previous themes), and bumping the SKD targets to 32

I tested it by setting the connection type to ConnectIQ.IQConnectType.TETHERED in MainActivity.kt here:

connectIQ = ConnectIQ.getInstance(this, ConnectIQ.IQConnectType.WIRELESS)

- Sending messages must be done outside of the UI thread -> use coroutines for this
- Kotlin coroutines require a scope, therefore I included the androidx lifecycle dependency,
and switched the DeviceActivity to be an AppCompatActivity (otherwise the lifecycle scope
did not work)
- This also required changing the themes to be AppCompat themes (the design should be equal
to the previous themes), and bumping the SKD targets to 32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants