In order to connect to Stringee Server, you will need access to the authentication credential: access_token. In production application, the access_token should be generated by your server described here: Client authentication, sample code generates access token here: https://github.com/stringeecom/server-samples/tree/master/access_token.
But to speed things up we will just hard code the value for now:
private String token;
To do this, go to Dashboard -> Tools -> Generate Access token and generates an access_token.
Next, we will connect to Stringee Server. You must do this before you can send or receive a message
Add a StringeeClient property to your Activity
private StringeeClient client;
The StringeeClient class is defined in Stringee SDK. It includes methods interacting with Stringee Server.
Instantiate the StringeeClient object and call its connect(token) method:
client = new StringeeClient(this);
client.connect(token);
To interact with Stringee Server connection, you will need register a StringeeConnectionListener interface with StringeeClient object before connecting.
client.setConnectionListener(new StringeeConnectionListener() {
@Override
public void onConnectionConnected(StringeeClient stringeeClient, boolean isReconnecting) {
}
@Override
public void onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) {
}
@Override
public void onIncomingCall(StringeeCall stringeeCall) {
}
@Override
public void onConnectionError(StringeeClient stringeeClient, StringeeError stringeeError) {
}
@Override
public void onRequestNewToken(StringeeClient stringeeClient) {
}
@Override
public void onCustomMessage(String from, JSONObject msg) {
}
});
To listen for object (Conversation, Message) change events, you will need register a ChangeEventListenter interface:
stringeeClient.setChangeEventListenter(new ChangeEventListenter() {
@Override
public void onChangeEvent(StringeeChange change) {
}
});