Client guide
Android development guide
Integrate floo-android, choose synchronous services or asynchronous managers, implement chat and groups, bind vendor push, and add voice & video.
The Android SDK exposes the shared native client through Java, SWIG, and JNI. Each feature has a low-level synchronous service and a high-level asynchronous manager. Keep the choice consistent within a feature and never run blocking service calls on the main thread.
Architecture and API layers
| Feature | Synchronous service | Asynchronous manager |
|---|---|---|
| Users | BMXUserService | BMXUserManager |
| Chat | BMXChatService | BMXChatManager |
| Contacts | BMXRosterService | BMXRosterManager |
| Groups | BMXGroupService | BMXGroupManager |
| Push | BMXPushService | BMXPushManager |
Models such as BMXMessage, BMXConversation, BMXGroup, BMXRosterItem, and BMXUserProfile are shared across both layers. Listener classes deliver lifecycle and data-change events independently of the call style.
Install, permissions, and shrinker rules
- Download the AAR release into the app libs directory, or add the matching JAR and ABI-specific native libraries.
- Declare the network, storage/media, notification, camera, and microphone permissions actually used by your product and Android target level.
- Load the floo native library once from the application entry point.
- Keep im.floo.floolib classes in R8/ProGuard according to the release integration guide.
- Package only supported ABIs and test each distribution split on a physical device.
static {
System.loadLibrary("floo");
}Initialise BMXClient
// 设置存储路径
String appPath = AppContextUtils.getAppContext().getFilesDir().getPath();
File dataPath = new File(appPath + "/data_dir");
File cachePath = new File(appPath + "/cache_dir");
dataPath.mkdirs();
cachePath.mkdirs();
// 设置推送平台对应的ID
String pushId = getPushId();
// 配置sdk config
BMXSDKConfig config = new BMXSDKConfig(BMXClientType.Android, "1", dataPath.getAbsolutePath(),
cachePath.getAbsolutePath(), TextUtils.isEmpty(pushId) ? "MaxIM" : pushId);
config.setConsoleOutput(true);
config.setLogLevel(BMXLogLevel.Debug);
// 初始化BMXClient
BMXClient bmxClient = BMXClient.create(conf);Register, sign in, restore, and sign out
bmxClient.getUserManager().signUpNewUser("zhangsan", "sFo!slk1x", new BMXDataCallBack<BMXUserProfile>(){
@Override
public void onResult(BMXErrorCode bmxErrorCode, BMXUserProfile bmxUserProfile) {
//返回profile
}
}); // 参数:username(用户名) password(密码)
bmxClient.getUserService().signInByName("zhangsan", "sFo!slk1x");
bmxClient.getUserService().fastSignInByName("zhangsan", "sFo!slk1x");- Use normal sign-in when a fresh token is needed and fast sign-in when the supported cached-token flow applies.
- Use a backend-issued user token for token sign-in; never embed the server access token in the APK.
- Observe connection and sign-in listeners so the UI distinguishes authentication, connection, and synchronisation states.
- On sign-out, stop push or unbind the vendor token for the account before showing another user's data.
Conversations and message history
BMXConversationList cl = bmxClient.getChatService().getAllConversations();
for (int i=0; i<cl.size(); i++){
BMXConversation c = cl.get(i);
Log.e("conversation id:",""+c.conversationId());
}Use the asynchronous manager equivalent when results feed the UI. Page message history, preserve conversation IDs as stable keys, and apply unread and receipt changes from listeners rather than polling.
Users, contacts, and privacy controls
| Area | Operations |
|---|---|
| Profile | Fetch and update the signed-in user's profile, avatar, password, and notification settings. |
| Contact requests | Apply, accept, decline, and list pending applications. |
| Contacts | Fetch details, set aliases, remove contacts, and refresh cached state. |
| Block list | Add, remove, and enumerate blocked users. |
| Listeners | Handle relationship, profile, and application changes; remove listeners with their owner. |
Groups, roles, and shared resources
Use BMXGroupService or BMXGroupManager for the complete group lifecycle: create, destroy, join, leave, invite, handle applications, transfer ownership, promote administrators, mute or block members, edit policy, publish announcements, and manage shared files.
| Before showing an action | Check |
|---|---|
| Edit profile or policy | Current role and the group's modification policy. |
| Invite or remove members | Membership, group type, capacity, and admin permissions. |
| Mute or block | Target role plus current user's admin or owner permission. |
| Delete files or announcements | Uploader/author identity and administrator permission. |
Build every supported message type
//参数说明: from(发送者id) to(接收者id) type(单群聊类型) text(文本内容)
BMXMessage msg = BMXMessage.createMessage(from, to, type, to, text);//参数说明: from(发送者id) to(接收者id) type(单群聊类型) w(图片宽) h(图片高) path(图片本地路径) size(图片大小)
BMXImageAttachment.Size size = new BMXMessageAttachment.Size(w, h);
BMXImageAttachment imageAttachment = new BMXImageAttachment(path, size);
BMXMessage msg = BMXMessage.createMessage(from, to, type, to, imageAttachment);| Content | Model |
|---|---|
| Text | BMXMessage.createMessage with text content. |
| Image | BMXImageAttachment with path and dimensions. |
| File | BMXFileAttachment with path and display name. |
| Location | BMXLocationAttachment with latitude, longitude, and address. |
| Voice | BMXVoiceAttachment with path and duration. |
| Video | BMXVideoAttachment and the metadata required by the current SDK. |
| Custom | Extension/config fields documented for the target SDK version. |
Send, forward, retry, recall, and download
//发送消息状态,需要注册消息接收监听
bmxClient.getChatManager().sendMessage(msg);- Register the chat listener before sending so status changes are not missed.
- Use forwardMessage for an SDK-created forward message and resendMessage only after failure.
- Recall within the server window and update local state from recall callbacks.
- Keep source files readable until upload completes or retry is no longer possible.
- Download attachments through BMXChatManager and expose progress, cancel, retry, and storage errors in the UI.
Chat listener contract
private BMXChatServiceListener mChatListener = new BMXChatServiceListener() {
@Override
public void onStatusChanged(BMXMessage msg, BMXErrorCode error) {
//消息状态更新
}
@Override
public void onAttachmentStatusChanged(BMXMessage msg, BMXErrorCode error, int percent) {
//附件状态更新
}
@Override
public void onRecallStatusChanged(BMXMessage msg, BMXErrorCode error) {
//撤回状态更新
}
@Override
public void onReceive(BMXMessageList list) {
//收到消息
}
@Override
public void onReceiveSystemMessages(BMXMessageList list) {
//收到系统通知
}
@Override
public void onReceiveReadAcks(BMXMessageList list) {
//收到已读回执
}
@Override
public void onReceiveDeliverAcks(BMXMessageList list) {
//收到消息到达回执
}
@Override
public void onReceiveRecallMessages(BMXMessageList list) {
//收到撤回消息通知
}
@Override
public void onAttachmentUploadProgressChanged(BMXMessage msg, int percent) {
//附件上传进度更新
}
};Android vendor push
- Upload credentials for every enabled vendor channel in the Lanying console.
- Integrate the vendor SDKs required by the devices your application supports.
- Select BMXPushProviderType from the actual device/vendor environment.
- Start BMXPushService or BMXPushManager and bind the returned vendor device token.
- Refresh the binding whenever a provider rotates the token; stop or unbind it on sign-out.
| Push area | SDK responsibility |
|---|---|
| Lifecycle | start, stop, resume, and status. |
| Identity | SDK token, vendor device token, alias, and certificate retrieval. |
| Targeting | Tags and aliases, subject to server limits. |
| Preferences | Enable switch, allowed hours, and quiet hours. |
| Events | BMXPushServiceListener token and message callbacks. |
Voice & video on Android
floo-android provides call signalling and floo-rtc-android provides the media engine and render views. Complete sign-in and message delivery first, then add RTCRenderView, obtain the engine from RTCManager, and register both engine and call-signalling listeners.
| State | Required handling |
|---|---|
| Outgoing invitation | Create call configuration, send the call message, and retain its call ID. |
| Incoming invitation | Validate call state, show the incoming UI, then answer or reject once. |
| Connected | Join the room, publish local media, subscribe, and bind render views. |
| Interrupted | Handle permissions, audio route, app lifecycle, network change, and engine errors. |
| Ended | Send hang-up when appropriate, leave, release render resources, and remove every listener. |
Android release checklist
- Run synchronous services off the main thread and marshal UI changes back to it.
- Test every packaged ABI and verify R8/ProGuard keeps required SDK bindings.
- Test scoped storage and media permissions on the minimum and target Android versions.
- Test notification permission, every configured vendor channel, token refresh, and account switching.
- Test chat listeners across Activity/Fragment recreation and remove old instances.
- Test voice & video on physical devices with Bluetooth, interruptions, backgrounding, and network handover.