Add a Conversation to an Android app

Initialize the OpenWeb SDK and configure the Conversation in your Android app.

When implemented, a user sees the following displayed below your article in your article Activity or Fragment:

  • Preview of comments (preConversationFragment) from the conversation
  • Text box to enter comments
  • Button to show all comments

If a user clicks the button to see more comments, the SDK opens the Activity which displays all comments from the conversation.

If a user clicks on the text box, the creation screen appears to enable the user to type a comment.


Implementation

Use the following steps to initialize the SDK and configure the Conversation.

  1. In onCreate() of the application class, initialize the OpenWeb SDK with your Spot_ID.
SpotIm.init(
    this,
    "SPOT_ID"
)
SpotIm.init(
    context,
    "SPOT_ID"
);

Or with success callback:

SpotIm.init(
    this,
    "SPOT_ID",
    object: SpotVoidCallback {
        override fun onSuccess() {
            //do Something ...
        }

        override fun onFailure(exception: SpotException) {
            when(exception) {
                is SPServerErrorException -> { } // do something
                is SPNoInternetConnectionException -> { } // do something
                is SPSdkDisabeledException -> { } // do something
                else -> { } // do something 
            }
        }
    }
)
SpotIm.init(
    context,
    "SPOT_ID",
    new SpotVoidCallback() {
        @Override
        public void onSuccess() {
            //do Something ...
        }

        @Override
        public void onFailure(@NotNull SpotException exception) {
            if (exception instanceof SPNoInternetConnectionException) {
                // do something 
            } else if (exception instanceof SPServerErrorException) {
                // do something 
            } else if (exception instanceof SPSdkDisabeledException) {
                // do something 
            } else {
                // do something 
            }
        }
    }
);

  1. In onCreate() of an article activity, add the pre-conversation fragment to the Activity.
SpotIm.getPreConversationFragment(CONVERSATION_ID, object :
    SpotCallback<Fragment> {
        override fun onSuccess(fragment: Fragment) {
            //do Something ...
        }

        override fun onFailure(exception: SpotException) {
            //do Something ...
          }
})
SpotIm.getPreConversationFragment(CONVERSATION_ID,new SpotCallback<Fragment>() {
    @Override 
    public void onSuccess(Fragment fragment) { 
        //doSomething...
    } 
    
    @Override 
    public void onFailure(SpotException exception) {    
        //doSomething...
    } 
});


Get a comment counter

To show your users the engagement level of multiple Conversations, you can display the number of user comments that have been posted on each article on your main screen.

The following code example shows how to get and display a comment counters for multiple conversations.

SpotIm.getConversationCounters(listOf(<POST_ID>), object : SpotCallback<Map<String, ConversationCounters>> {
    override fun onSuccess(response: Map<String, ConversationCounters>) {
        val counters = response[<SPECIFIC_POST_ID>]
        counters?.let {
            print(it.comments)
            print(it.replies)
        }
    }

    override fun onFailure(exception: SpotException) {
        // Do something
    }
})
SpotIm.getConversationCounters(Arrays.asList(<POST_ID>), new SpotCallback<Map<String, ConversationCounters>>() {
    @Override
    public void onSuccess(Map<String, ConversationCounters> response) {
        ConversationCounters counters = response.get(<SPECIFIC_POST_ID>);
        System.out.println(counters.getComments());
        System.out.println(counters.getReplies());
    }

    @Override
    public void onFailure(SpotException exception) {
        // Do something
    }
});


Did this page help you?