Mobile SDKs
Android SDK
Install and use the STINGIM Android SDK: setup, user identity, chat UI, events and token storage.
The Android SDK (com.stingim:stingim-channel, version 1.1.0) provides a built-in chat screen and a headless API for custom UIs. It is written in Java and works from Kotlin.
Requirements
| Item | Value |
|---|---|
minSdk | 23 (Android 6.0) |
compileSdk / targetSdk used by the SDK | 37 |
| Java language level | 17 |
| Android Gradle Plugin | 9.3.1 (tested) |
| Main dependencies | OkHttp 4.12, Gson, Room 2.8, Glide 5, EventBus, PhotoView, AndroidX AppCompat / Material / RecyclerView |
Install
The SDK is published in the STINGIM Maven repository on this site — no account or credentials needed. Add the repository next to google() and mavenCentral():
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url "https://stingim.com/sdk/maven" }
}
}dependencies {
implementation 'com.stingim:stingim-channel:1.1.0'
}With the Kotlin DSL:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://stingim.com/sdk/maven") }
}
}dependencies {
implementation("com.stingim:stingim-channel:1.1.0")
}The repository serves the AAR, a sources JAR, the POM, Gradle module metadata and md5/sha1/sha256/sha512 checksums, so Android Studio shows the SDK sources. Transitive dependencies resolve from google() and mavenCentral(). PhotoView 2.3.0, the only dependency that is not on Maven Central, is mirrored unmodified in the same repository, so you do not need JitPack. If your build uses an older allprojects { repositories { … } } block, add the maven { url "https://stingim.com/sdk/maven" } line there instead.
Direct AAR download
If you cannot use a Maven repository, download stingim-channel-1.1.0.aar and check its SHA-256 against the downloads page. A bare AAR carries no dependency information, so declare the SDK's dependencies yourself (PhotoView then needs maven { url "https://stingim.com/sdk/maven" } or JitPack):
dependencies {
implementation files('libs/stingim-channel-1.1.0.aar')
implementation 'androidx.core:core-ktx:1.19.0'
implementation 'androidx.appcompat:appcompat:1.8.0'
implementation 'com.google.android.material:material:1.14.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.2'
implementation 'androidx.recyclerview:recyclerview:1.4.0'
implementation 'androidx.room:room-runtime:2.8.4'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
implementation 'com.google.code.gson:gson:2.14.0'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.github.bumptech.glide:glide:5.0.9'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
}The Maven route is recommended: it picks up the dependency list and the sources automatically.
Initialise
Production: token from your server
Your server exchanges the App Secret for a visitor token (how) and returns contactId, contactToken and channelId to the app:
Stingim.initWithToken(this, contactId, contactToken, channelId,
tenantId, projectId, new Stingim.InitCallback() {
@Override public void onSuccess(String contactId, String token) {
Stingim.startChat(MainActivity.this, "Support");
}
@Override public void onError(String error) { /* show an error */ }
});tenantId and projectId are optional; a five-argument overload initWithToken(context, contactId, contactToken, channelId, callback) exists too.
Development: SDK exchanges the App Secret
Only for development or controlled environments. Do not hard-code the App Secret in a released app.
import com.stingim.Stingim;
Stingim.init(this, "your_plugin_id", "your_app_secret", "your_channel_id",
new Stingim.InitCallback() {
@Override
public void onSuccess(String contactId, String token) {
// initialised; the WebSocket connects automatically
Stingim.startChat(MainActivity.this, "Support"); // open the built-in chat screen
}
@Override
public void onError(String error) {
// wrong credentials, network error…
}
});Initialising again with a different identity fails with SDK is already initialized with a different identity; disconnect first — call Stingim.disconnect() first.
Configuration
Call setConfig before init:
StingimConfig config = new StingimConfig()
.setApiBaseUrl("https://api.stingim.com") // REST base URL (default)
.setSocketBaseUrl("wss://msg.stingim.com") // gateway base URL (default; /visitor is appended)
.setDebugMode(true);
Stingim.setConfig(config);
Stingim.init(this, pluginId, appSecret, channelId, callback);Other options: setProjectId (needed in direct mode to show the AI disclosure and business-hours notice), autoConnect, showNotification, playSoundOnMessage, vibrateOnMessage, heartbeatInterval (fallback only — the server's value wins), reconnectAttempts, reconnectDelay.
User identity
To bind the logged-in user to the contact (so history follows them across devices), sign the user on your server exactly as for the web widget: user_hash = hex(HMAC-SHA256(secret, user_id)), or of user_id + ":" + exp with an expiry.
In production, send the signed fields to open-create-contact from your server (token exchange). In direct mode, pass them to the SDK:
StingimIdentity identity = StingimIdentity.builder(userId, userHash)
.userHashExp(exp) // only if you signed "user_id:exp"
.userName("Jane Doe") // display only, not covered by the signature
.userEmail("[email protected]")
.build();
Stingim.init(context, pluginId, appSecret, channelId, identity, callback);
Stingim.getIdentityStatus(); // anonymous / verified / unverified / rejected
Stingim.isIdentityVerified();When the user logs out, call Stingim.disconnect(). initWithUser(...) is deprecated: a plain user id is not a credential.
Built-in chat UI
Stingim.startChat(context); // default title
Stingim.startChat(context, "Support"); // custom titlestartChat opens ChatActivity and throws IllegalStateException if the SDK is not initialised. The screen supports text, emoji, images, files, voice messages, interactive buttons, queue position and the satisfaction rating dialog. Its strings default to English with a Chinese (values-zh) translation; override any stingim_* string resource to change wording. Built-in styles are Theme.STINGIM.Chat and Theme.STINGIM.ImagePreview.
Custom UI
Use the managers when you build your own screens. All callbacks run on the main thread.
StingimConversationManager conv = StingimConversationManager.getInstance(context);
StingimMessageManager msg = StingimMessageManager.getInstance(context);
conv.startChat(title, startCallback);
String conversationId = conv.effectiveConversationId();
msg.sendTextMessage(conversationId, "Hello");
msg.fetchServerHistory(30, historyCallback);
msg.loadMessages(conversationId, offsetId, pageSize, pageCallback);
msg.markAsRead(conversationId, lastMessageId);
msg.sendTyping(conversationId);
// interactive messages (buttons)
StingimInteractive card = message.getInteractive();
msg.sendInteractionReply(message, card.getActions().get(0));
// files: upload, then send
StingimFileService files = StingimFileService.getInstance(context);
files.upload(file, "photo.jpg", "image/jpeg", uploadCallback); // onUploaded → msg.sendMediaMessage(conversationId, uploaded)
files.resolvePreviewUrl(message.getContent(), previewCallback); // signed URL for incoming media
// queue and unread
conv.getQueueInfo(conversationId, queueCallback);
conv.getUnreadCount(conversationId, unreadCallback);Before the first message there is no conversation yet; the SDK sends it with a provisional id and switches to the real conversation id automatically.
Events and listeners
| Listener | Methods |
|---|---|
StingimMessageManager.MessageListener | onMessageAdded(StingimMessage), onMessageListChanged() |
StingimMessageManager.MessageStatusListener | onMessageStatusChanged(StingimMessage) — includes rate_limited |
StingimMessageManager.EvaluationListener | onEvaluationInvite(StingimEvaluationInvite), onEvaluationSubmitted(StingimEvaluation), onEvaluationComplete(String) |
StingimMessageManager.TypingListener | onTypingStatusChanged(conversationId, userId, userName, userType, isTyping) |
StingimSocketClient.ConnectionListener | onConnected(), onDisconnected(String), onError(String), onOnlineSuccess() |
StingimSocketClient.QueueListener | onQueueStatusUpdate(...), onConversationStatusChanged(String, int), onRobotAccess(String, boolean) |
StingimSocketClient.MessageListener | onReceiveMessage(...), onMessageError(...), onResync(...), onReady(), onStreamDelta(...) (streaming AI replies) |
StingimConversationManager.ConversationListener | onConversationChanged(...), onQueueStatusChanged(...) |
StingimAuthListener | onTokenInvalid(StingimError), onReauthenticated(String contactId, boolean contactChanged), onReauthenticationFailed(StingimError) |
Token lifecycle
Stingim.setAuthListener(new StingimAuthListener() {
@Override public void onTokenInvalid(StingimError error) { /* e.g. "session expired" */ }
@Override public void onReauthenticated(String contactId, boolean contactChanged) { }
@Override public void onReauthenticationFailed(StingimError error) {
// token mode: fetch a new token from your server, then Stingim.initWithToken(...)
}
});StingimError.Code: TOKEN_INVALID, IDENTITY_REJECTED, SESSION_EVICTED, RATE_LIMITED, NETWORK, SERVER, INVALID_ARGUMENT, UNSUPPORTED.
- A rejected token (HTTP 401, business code 502, or a gateway
unauthorized) is cleared. In direct mode the SDK re-bootstraps automatically; in token mode, get a new token and callinitWithTokenagain. session_evicted(the same visitor connected elsewhere) does not reconnect automatically.
Token storage
The visitor token is encrypted with a non-exportable AES-256-GCM key in the Android Keystore and stored in the SDK's private SharedPreferences. If the Keystore is unavailable the token is kept in memory only. A backup restored on a new device cannot decrypt it, so the SDK simply starts a new session. Stingim.disconnect() clears the token and identity. Messages are cached locally in a Room database. Logs never contain tokens, the App Secret or full message frames.
Lifecycle helpers
Stingim.isInitialized();
Stingim.isConnected();
Stingim.connect(); // when autoConnect is false
Stingim.disconnect(); // disconnect and clear local auth data — call on logout
Stingim.getVersion(); // "1.1.0"Permissions and manifest
The SDK's manifest merges INTERNET, ACCESS_NETWORK_STATE, RECORD_AUDIO (voice messages), VIBRATE, POST_NOTIFICATIONS and WRITE_EXTERNAL_STORAGE (API ≤ 28 only), a FileProvider with authority ${applicationId}.fileprovider, and the non-exported ChatActivity / ImagePreviewActivity. Request the runtime permissions (microphone, notifications on Android 13+) before using those features. A cleartext test server needs android:usesCleartextTraffic="true"; production uses HTTPS/WSS only.
R8/ProGuard: the SDK ships consumer rules (-keep class com.stingim.** { *; }), so no extra configuration is needed.
Not supported in 1.0
- Quote replies —
sendReplyMessagesends plain text. StingimApi.getConversationDetail(agent-only on the backend).
See Troubleshooting if something does not work.
Found a mistake? Email [email protected]
