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

FeatureSynchronous serviceAsynchronous manager
UsersBMXUserServiceBMXUserManager
ChatBMXChatServiceBMXChatManager
ContactsBMXRosterServiceBMXRosterManager
GroupsBMXGroupServiceBMXGroupManager
PushBMXPushServiceBMXPushManager

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

  1. Download the AAR release into the app libs directory, or add the matching JAR and ABI-specific native libraries.
  2. Declare the network, storage/media, notification, camera, and microphone permissions actually used by your product and Android target level.
  3. Load the floo native library once from the application entry point.
  4. Keep im.floo.floolib classes in R8/ProGuard according to the release integration guide.
  5. Package only supported ABIs and test each distribution split on a physical device.
Load the native libraryjava
    static {
        System.loadLibrary("floo");
    }

Initialise BMXClient

Application initialisationjava
    // 设置存储路径
    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);
The legacy sample is preserved verbatim and uses both config and conf. Confirm the current generated constructor and variable name in the Android reference before integration; fix the upstream sample rather than silently changing the migrated block.

Register, sign in, restore, and sign out

Asynchronous registrationjava
   bmxClient.getUserManager().signUpNewUser("zhangsan", "sFo!slk1x", new BMXDataCallBack<BMXUserProfile>(){
        @Override
        public void onResult(BMXErrorCode bmxErrorCode, BMXUserProfile bmxUserProfile) {
           //返回profile
        }
   	});
Synchronous sign-injava
	// 参数: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

Synchronous conversation listjava
   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

AreaOperations
ProfileFetch and update the signed-in user's profile, avatar, password, and notification settings.
Contact requestsApply, accept, decline, and list pending applications.
ContactsFetch details, set aliases, remove contacts, and refresh cached state.
Block listAdd, remove, and enumerate blocked users.
ListenersHandle 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 actionCheck
Edit profile or policyCurrent role and the group's modification policy.
Invite or remove membersMembership, group type, capacity, and admin permissions.
Mute or blockTarget role plus current user's admin or owner permission.
Delete files or announcementsUploader/author identity and administrator permission.

Build every supported message type

Text messagejava
//参数说明: from(发送者id)  to(接收者id)  type(单群聊类型)  text(文本内容)
BMXMessage msg = BMXMessage.createMessage(from, to, type, to, text);
Image messagejava
//参数说明: 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);
ContentModel
TextBMXMessage.createMessage with text content.
ImageBMXImageAttachment with path and dimensions.
FileBMXFileAttachment with path and display name.
LocationBMXLocationAttachment with latitude, longitude, and address.
VoiceBMXVoiceAttachment with path and duration.
VideoBMXVideoAttachment and the metadata required by the current SDK.
CustomExtension/config fields documented for the target SDK version.

Send, forward, retry, recall, and download

Asynchronous sendjava
    //发送消息状态,需要注册消息接收监听
    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

Core receive callbacksjava
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

  1. Upload credentials for every enabled vendor channel in the Lanying console.
  2. Integrate the vendor SDKs required by the devices your application supports.
  3. Select BMXPushProviderType from the actual device/vendor environment.
  4. Start BMXPushService or BMXPushManager and bind the returned vendor device token.
  5. Refresh the binding whenever a provider rotates the token; stop or unbind it on sign-out.
Push areaSDK responsibility
Lifecyclestart, stop, resume, and status.
IdentitySDK token, vendor device token, alias, and certificate retrieval.
TargetingTags and aliases, subject to server limits.
PreferencesEnable switch, allowed hours, and quiet hours.
EventsBMXPushServiceListener 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.

StateRequired handling
Outgoing invitationCreate call configuration, send the call message, and retain its call ID.
Incoming invitationValidate call state, show the incoming UI, then answer or reject once.
ConnectedJoin the room, publish local media, subscribe, and bind render views.
InterruptedHandle permissions, audio route, app lifecycle, network change, and engine errors.
EndedSend 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.