Bit6 messaging capabilities are accessed via MessageClient.

MessageClient messageClient = bit6.getMessageClient();

Send Message

Address to = Address.parse("usr:john");

To follow the message progress as it is being sent implement MessageStatusListener.

public void onMessageStatusChanged(Message m, int state) {
    switch(state) {
        case Message.STATUS_SENDING:
        case Message.STATUS_FAILED:

Delete Message

To delete a message you need its _id value, usually retrived from a cursor.

long msgId = cursor.getLong(cursor.getColumnIndex(Contract.Messages._ID));
messageClient.deleteMessage(msgId, new ResultHandler() {
    public void onResult(boolean success, String msg) {}

Message Details

Message flags contain information about the message type and status:

int flags = cursor.getInt(cursor.getColumnIndex(Messages.FLAGS));
// Is this an incoming message?
boolean isIncoming = Message.isIncoming(flags)
// Get message type: Message.TYPE_TEXT, Message.TYPE_ATTACH etc
int type = Message.getType(flags);
// Get message status: Message.STATUS_SENT, Message.STATUS_DELIVERED
int status = Message.getStatus(flags);

Incoming Messages

To get notified about new incoming messages even when your app is not in the foreground:

Step 1. Register Broadcast Receiver for intent in your Manifest.xml

<receiver android:name=".IncomingMessageReceiver" android:enabled="true">
        <action android:name=""></action>

Step 2. Create a receiver class which extends BroadcastReceiver.

public class IncomingMessageReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        if (intent.getExtras() != null){
            String content = intent.getStringExtra(Bit6.INTENT_EXTRA_CONTENT);
            String senderName = intent.getStringExtra(Bit6.INTENT_EXTRA_NAME);


Get all conversations:

Cursor cursor = getContentResolver().query(
        null, null, null, null);

Get all conversations with last message content:

Cursor cursor = getContentResolver().query(
        null, null, null, null);

Get all messages for a conversation - query by conversation _id:

Cursor cursor = getContentResolver().query(
        Contract.Messages.CONTENT_URI, null,
        Contract.Messages.CONVERSATION_ID + "=?", new String[] {
        Contract.Messages.CREATED + " ASC");


Send Photo or Video

When creating an outgoing message, specify the content type and the path to the file to send.

Address to = Address.parse("usr:john");
messageClient.compose(to).text("Yo").attach("/path/to/file.mp4", "video/mp4").send(statusListener);

For these messages you get additional status updates via MessageStatusListener:

public void onMessageStatusChanged(Message m, int state) {
    switch(state) {
        case Message.STATUS_PREPARING:
        case Message.STATUS_UPLOADED:
        case Message.STATUS_SENDING:
        case Message.STATUS_FAILED:

Attachment URI

If message type is Contract.Messages.TYPE_ATTACH you can retrieve the attachment information from message's data.

String dataStr = cursor.getString(cursor.getColumnIndex(Contract.Messages.DATA));
Message.Data data = Message.getData(dataStr, flags);
if (data.isAttachment()) {
    Message.Attachment attach = (Message.Attachment)data;
    // Attachment content type
    String contentType = attach.getContentType();
    // URI to access the attachment data
    String uri = attach.getUri();

Thumbnail Image

Some messages (photo, video, location) may have a thumbnail image. Note that you need to handle the image download and caching in your app.

String uri = cursor.getString(cursor.getColumnIndex(Contract.Messages.THUMB_URI));


To send a location message with text, latitude and longitude:

Address to = Address.parse("usr:john");
messageClient.compose(to).geo(40.192324, 44.504161).send(statusListener);

If message type is Contract.Messages.TYPE_GEOLOC you can retrieve the geo location information from the message data.

String dataStr = cursor.getString(cursor.getColumnIndex(Contract.Messages.DATA));
Message.Data data = Message.getData(dataStr, flags);
if (data.isGeoLocation()) {
    Message.GeoLocation geo = (Message.GeoLocation)data;
    // URI to view location in a map application
    String uri = geo.getMapUri();
    // Get the location
    double lat = geo.getLatitude();
    double lng = geo.getLongitude();


Bit6 notification capabilities are accessed via NotificationClient

NotificationClient notificationClient = bit6.getNotificationClient();

Get notified when connection is established or closed, another user is typing a message, or on any other real-time notification:

notificationClient.addListener(new NotificationClient.Listener() {
    public void onTypingReceived(String from) {
        Log.v(TAG, "Typing from: " + from);
    public void onNotificationReceived(String from, String type, JSONObject data) {
        Log.e(TAG, "Notification: " + data.toString());
    public void onConnectedChanged(boolean isConnected) {
        Log.e(TAG, "RT is connected " + isConnected);


Send 'typing' notification:

Address to = Address.parse("usr:john");


Send custom notification:

Address to = Address.parse("usr:john");
notificationClient.sendNotification(to, "mytype");


A Group contains a set of properties (group id, meta information, permissions) and has members. A user can be a member of multiple groups.


Get all groups that this user is a member of:

Cursor cursor = getContentResolver().query(Contract.Groups.CONTENT_URI,null, null, null, null);

Create a new group. The current user will become the group administrator.

// groupId, permissions and meta are optional and can be null
bit6.createGroup(groupId, permissions, meta, handler);

Update a group:

bit6.updateGroup(groupId, permissions, meta, handler);

Delete a group:

bit6.deleteGroup(groupId, handler);


Join a group:

// role is one of constants from Group.Permissions class, e.g Group.Permissions.ROLE_USER
bit6.joinGroup(groupId, role, handler);

Leave a group:

bit6.leaveGroup(groupId, handler);

Invite a member to a group:

bit6.inviteGroupMember(groupId, identity, role, handler);

Kick a member from a group:

bit6.kickGroupMember(groupId, identity, handler);