1

I am trying to setup PubNub in my Android app. It works perfectly fine except for one thing. How do I set a dynamic channel name:

I need to the channel name to be for example:

app.account_14.general_channel

The account id (14) will be dynamic depending on which user is logged in.

I am using this exact code from Pubnub:

https://github.com/pubnub/java/blob/master/android/examples/SubscribeAtBoot/src/com/pubnub/examples/subscribeAtBoot/PubnubService.java

Thankful for all help!

Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175

1 Answers1

5

Once you have your PubNub instance initialized, you can subscribe to as many channels as you want. Many developers will have their clients subscribe to a global channel for updates, and then a user channel for private communication.

Right now in your code, you're subscribing to one channel:

String channel = "hello_world";

...And then later:

try {
  pubnub.subscribe(new String[] {channel}, new Callback() {

You can feel free to compose your own channel name based on your user's ID and subscribe to this channel instead of, or in addition to, your existing channel. (If this ID needs to be persisted, check out this link for information about storing that data in a bundle.)

Let me know how it goes!

Community
  • 1
  • 1
drnugent
  • 1,545
  • 9
  • 22