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

How to send broadcast when tile button is clicked? #80

Closed
Thomas-Vos opened this issue Mar 20, 2021 · 2 comments
Closed

How to send broadcast when tile button is clicked? #80

Thomas-Vos opened this issue Mar 20, 2021 · 2 comments

Comments

@Thomas-Vos
Copy link

I checked out the Wear Tiles Sample and have a question about the buttons.

The tiles media sample contains a Play icon button. As described in the sample, the buttons do not do anything at the moment. However, I am not sure how to set the click action to send a broadcast.

I would assume this play button is supposed to start the music without opening the app. I would like to do something similar, turn on a smart light without opening the app.

However, I cannot find an ActionBuilders.Action that sends a broadcast. It would be great if you could add a click action to this sample so it is clear how to actually implement a play button or something similar.

@joelphilippage
Copy link

I set the ID and then at the beginning of onTileRequest, check request params. If the lastClickableId is your click, you can just run any function there including sending a broadcast.

Here is my code:

Set Click:

.setClickable(ModifiersBuilders.Clickable.builder()
.setId(if(requestParams.state.lastClickableId == START_ID) STOP_ID else START_ID)
.setOnClick(ActionBuilders.LoadAction.builder())))

At the beginning of onTileRequest:

if(requestParams.state.lastClickableId == START_ID)
            startServer()
        else
            stopServer()

My startServer and stopServer functions send broadcasts.

@alexvanyo
Copy link
Contributor

It sounds like this is resolved!

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

No branches or pull requests

3 participants