Skip to main content
Version: 0.1.x

Raise Hand using PubSub - Android

Let us see, how we can use PubSub to implement Raise Hand functionality. If you are not familiar with the PubSub mechanism and pubSub class, you can follow this guide.

Implementing Raise Hand

  1. First step in raise hand is choosing the topic which all the participants will publish and subscribe to know some participant raise their hand. We will be using RAISE_HAND as the topic for this one.
  2. On the raiseHand button, publish any message to that specific topic.
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

//...

findViewById(R.id.btnRaiseHand).setOnClickListener(view -> sendRaiseHandMessage());
}

private fun sendRaiseHandMessage() {
val publishOptions = PubSubPublishOptions()
publishOptions.setPersist(false)

// Sending the Message using the publish method
meeting!!.pubSub.publish("RAISE_HAND", "Raise Hand", publishOptions)
}
}
  1. Now let us show an alert to all the participants showing who raised the hand.
class MainActivity : AppCompatActivity() {

// PubSubMessageListener
var pubSubMessageListener =
PubSubMessageListener { message ->
// Partcipant raise hand
Toast.makeText(
this@MainActivity, message.senderName + " raise hand",
Toast.LENGTH_SHORT
).show()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_chat)

//...

// Subscribe for 'RAISE_HAND' topic
val pubSubMessageList = meeting!!.pubSub.subscribe("RAISE_HAND", pubSubMessageListener)
}
}

API Reference

The API references for all the methods and events utilised in this guide are provided below.

Got a Question? Ask us on discord