Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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