Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.


Repository files navigation

Matrix Client SDK for Java

Build Status

This project is no longer maintained.


Matrix SDK in Java 1.8 for:

  • Client -> Homeserver
  • Client -> Identity Server
  • Application Server -> Homeserver


Add to your project


repositories {
    maven {
        url ''

dependencies {
    compile 'io.kamax:matrix-java-sdk:<USE_LATEST_TAG_WITHOUT_LEADING_V>'



WARNING: This SDK was originally created to support projects and is therefore not necessarily complete. It will be built as the various projects evolve and grow. The SDK is therefore still in Alpha.

Getting started

Getting the client object

With .well-known auto-discovery:

_MatrixClient client = new MatrixHttpClient("");

With C2S API Base URL:

URL baseUrl = new URL("");
_MatrixClient client = new MatrixHttpClient(baseUrl);

Providing credentials

Access token:


Log in:

client.login(new MatrixPasswordCredentials(username, password));


// We will update this after each sync call
String syncToken = null;

// We sync until the process is interrupted via Ctrl+C or a signal
while (!Thread.currentThread().isInterrupted()) {
    // We provide the next batch token, or null if we don't have one yet
    _SyncData data = client.sync(;
    // We check the joined rooms
    for (JoinedRoom joinedRoom : data.getRooms().getJoined()) {
        // We get the relevant room object to act on it while we process
        _Room room = client.getRoom(joinedRoom.getId());
        for (_MatrixEvent rawEv : joinedRoom.getTimeline()) {
            // We only want to act on room messages
            if ("".contentEquals(rawEv.getType())) {
                MatrixJsonRoomMessageEvent msg = new MatrixJsonRoomMessageEvent(rawEv.getJson());
                // Ping?
                if (StringUtils.equals("ping", msgg.getBody())) {
                    // Pong!
    // We check the invited rooms
    for (InvitedRoom invitedRoom : data.getRooms().getInvited()) {
        // We auto-join rooms we are invited to
    // Done processing sync data. We save the next batch token for the next loop execution
    syncToken = data.nextBatchToken();

As an Application Service

Use MatrixApplicationServiceClient instead of MatrixHttpClient when creating the main client object.

To talk to the API as a virtual user, use the method createClient(localpart) on MatrixApplicationServiceClient, then processed normally.

Real-world usage

As a regular client

You can check the Send'n'Leave bot which make uses of this SDK in a more realistic fashion.
Direct link to the relevant code: here

As an Application Service


Contributions and PRs are welcome to turn this into a fully fledged Matrix Java SDK.
Your code will be licensed under AGPLv3.

To ensure code formatting consistency, we use Spotless.
Before opening any PR, make sure you format the code:

./gradlew spotlessApply

Your code must pass all existing tests with and must provide tests for any new method/class/feature.
Make sure you run:

./gradlew test