How to subscribe user with specific topic in OneSignal in Android?

Viewed 118

In Firebase you can subscribe user with the topic like this,

FirebaseMessaging.getInstance().subscribeToTopic("weather")
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            String msg = getString(R.string.msg_subscribed);
            if (!task.isSuccessful()) {
                msg = getString(R.string.msg_subscribe_failed);
            }
            Log.d(TAG, msg);
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    });

I am looking for a way to do the same in OneSignal.

1 Answers

1- You need to assign Tags To user in App.

  OneSignal.sendTag("subscribed", subscribed);

enter image description here

2- Create a Segment from User TAG. [ Plan Subscribed]

enter image description here

3- Send Notification to that Segment

enter image description here

Related