Pepper Talk is available as a gradle dependency. To pull in the dependency please add the following to your build.gradle
dependencies {
...
compile 'com.espreccino:peppertalk:0.4.17'
}
PepperTalk.getInstance(context)
.init(clientId,
clientSecret,
userId)
.connect();
PepperTalk.getInstance(context)
.chatWithParticipant(userId)
.topicId(topicId)
.topicTitle("Let ride!")
.start();
JSONObject object = new JSONObject();
object.put("hello", "its me!");
PepperTalk.getInstance(getActivity())
.sendCustomData(toUser,
text,
topicId,
topicTitle,
object, new JSONCallback() {
@Override
public void onSuccess(JSONObject jsonObject) {
...
}
@Override
public void onFail(PepperTalkError error) {
...
}
});
This callback is triggered whenever a message arrives for the user. Please note that the callback is invoked on a background thread and you will have to switch to the UI thread to do any UI updates.
/**
* Message Listener
* New incoming.
* Ideally used to update unread count on the UI
*/
public interface MessageListener {
public void onNewMessage(String userId, String topicId, int unreadCount);
}
This callback is triggered to notify the host application of the connection status.
/**
* Listen to Peppertalk connection status
*/
public interface ConnectionListener {
public void onConnecting(int status);
public void onConnected();
public void onConnectionFailed(PepperTalkError e);
}
When you receive a GCM notification you can check with PepperTalk to see if the notification is a Pepper Talk notification or not, and let the SDK handle the notification if it can. The SDK provides two functions one to check if the notification is from Pepper Talk and another to display the notification.
protected void onHandleIntent(Intent intent) {
//check if the notification is for PepperTalk
if (PepperTalk.getInstance(appContext).isNotificationFromPepperTalk(intent)) {
// handle the notification
PepperTalk.getInstance(appContext).handleNotification(intent,
R.drawable.ic_launcher,
soundUri);
} else {
//Handle your own notification
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}