com.hyphenate.chat.EMClient Java Examples

The following examples show how to use com.hyphenate.chat.EMClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseNotifier.java    From Social with Apache License 2.0 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMClient.getInstance().chatManager().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    viberateAndPlayTone(messages.get(messages.size()-1));
}
 
Example #2
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 点击进入群组详情
 *
 */
protected void toGroupDetails() {
    if (chatType == EaseConstant.CHATTYPE_GROUP) {
        EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
        if (group == null) {
            return;
        }
        if(chatFragmentListener != null){
            chatFragmentListener.onEnterToChatDetails();
        }
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        if(chatFragmentListener != null){
            chatFragmentListener.onEnterToChatDetails();
        }
    }
}
 
Example #3
Source File: HxSdkHelper.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 注册方法
 *
 * @param phone    手机号
 * @param pwd      密码
 * @param callBack 回调【注意回调会在子线程中】
 */
public void regist(final String phone, final String pwd, final FCCallBack callBack)
{
    ThreadManager.getInstance().addNewRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                EMClient.getInstance().createAccount(phone, pwd);
                if (callBack != null)
                    callBack.onSuccess(null);
            } catch (HyphenateException e)
            {
                KLog.e("HxSdk regist from server fail : hxErrCode = " + e.getErrorCode() + " , msg = " + e.getMessage());
                if (callBack != null)
                    callBack.onFail(FCError.REGIST_FAIL, FCError.getErrorMsgIdFromCode(e.getErrorCode()));
            }
        }
    });
}
 
Example #4
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 点击清空聊天记录
 *
 */
protected void emptyHistory() {
    String msg = getResources().getString(com.hyphenate.easeui.R.string.Whether_to_empty_all_chats);
    new EaseAlertDialog(getActivity(),null, msg, null,new EaseAlertDialog.AlertDialogUser() {

        @Override
        public void onResult(boolean confirmed, Bundle bundle) {
            if(confirmed){
                // 清空会话

                EMClient.getInstance().chatManager().deleteConversation(toChatUsername, true);
                messageList.refresh();
            }
        }
    }, true).show();;
}
 
Example #5
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
protected void sendMessage(EMMessage message){
    if(chatFragmentListener != null){
        //设置扩展属性
        chatFragmentListener.onSetMessageAttributes(message);
    }
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == EaseConstant.CHATTYPE_GROUP){
        message.setChatType(ChatType.GroupChat);
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        message.setChatType(ChatType.ChatRoom);
    }
    //发送消息
    EMClient.getInstance().chatManager().sendMessage(message);
    //刷新ui
    if(isMessageListInited) {
        messageList.refreshSelectLast();
    }
}
 
Example #6
Source File: EaseChatMessageList.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * init widget
 * @param toChatUsername
 * @param chatType
 * @param customChatRowProvider
 */
public void init(String toChatUsername, int chatType, EaseCustomChatRowProvider customChatRowProvider) {
    this.chatType = chatType;
    this.toChatUsername = toChatUsername;
    
    conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    messageAdapter = new EaseMessageAdapter(context, toChatUsername, chatType, listView);
    messageAdapter.setShowAvatar(showAvatar);
    messageAdapter.setShowUserNick(showUserNick);
    messageAdapter.setMyBubbleBg(myBubbleBg);
    messageAdapter.setOtherBuddleBg(otherBuddleBg);
    messageAdapter.setCustomChatRowProvider(customChatRowProvider);
    // 设置adapter显示消息
    listView.setAdapter(messageAdapter);
    
    refreshSelectLast();
}
 
Example #7
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
protected void onConversationInit(){
    // 获取当前conversation对象

    conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    // 把此会话的未读数置为0
    conversation.markAllMessagesAsRead();
    // 初始化db时,每个conversation加载数目是getChatOptions().getNumberOfMessagesLoaded
    // 这个数目如果比用户期望进入会话界面时显示的个数不一样,就多加载一些
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
        String msgId = null;
        if (msgs != null && msgs.size() > 0) {
            msgId = msgs.get(0).getMsgId();
        }
        conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
    }

}
 
Example #8
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
protected void sendMessage(EMMessage message){
    if (message == null) {
        return;
    }
    if(chatFragmentListener != null){
        //设置扩展属性
        chatFragmentListener.onSetMessageAttributes(message);
    }
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == EaseConstant.CHATTYPE_GROUP){
        message.setChatType(EMMessage.ChatType.GroupChat);
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        message.setChatType(EMMessage.ChatType.ChatRoom);
    }
    //发送消息
    EMClient.getInstance().chatManager().sendMessage(message);
    //刷新ui
    if(isMessageListInited) {
        messageList.refreshSelectLast();
    }
}
 
Example #9
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 点击进入群组详情
 * 
 */
protected void toGroupDetails() {
    if (chatType == EaseConstant.CHATTYPE_GROUP) {
        EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
        if (group == null) {
            Toast.makeText(getActivity(), R.string.gorup_not_found, 0).show();
            return;
        }
        if(chatFragmentListener != null){
            chatFragmentListener.onEnterToChatDetails();
        }
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
    	if(chatFragmentListener != null){
    		chatFragmentListener.onEnterToChatDetails();
    	}
    }
}
 
Example #10
Source File: MineFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
private void logout(){
    OkhttpUtil.logout(handler);
    //此方法为异步方法
    EMClient.getInstance().logout(true, new EMCallBack() {
        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub

        }
    });
}
 
Example #11
Source File: MineFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
private void logoutIMService(){
    //此方法为异步方法
    EMClient.getInstance().logout(true, new EMCallBack() {
        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub
            Log.d("SocialMainActivity", "成功退出环信服务器");
        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub
            Log.d("SocialMainActivity", "还没退出环信服务器");
        }
    });
}
 
Example #12
Source File: SettingFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
private void logoutIMService(){
    //此方法为异步方法
    EMClient.getInstance().logout(true, new EMCallBack() {
        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub
            Log.d("SocialActivity", "成功退出环信服务器");
        }

        @Override
        public void onProgress(int progress, String status) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(int code, String message) {
            // TODO Auto-generated method stub
            Log.d("SocialActivity", "还没退出环信服务器");
        }
    });
}
 
Example #13
Source File: EaseChatRowFile.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    String filePath = fileMessageBody.getLocalUrl();
    File file = new File(filePath);
    if (file != null && file.exists()) {
        // 文件存在,直接打开
        FileUtils.openFile(file, (Activity) context);
    } else {
        // 下载
        context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msgbody", message.getBody()));
    }
    if (message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) {
        try {
            EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
        } catch (HyphenateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
}
 
Example #14
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * input @
 * @param username
 */
protected void inputAtUsername(String username, boolean autoAddAtSymbol){
    if(EMClient.getInstance().getCurrentUser().equals(username) ||
            chatType != EaseConstant.CHATTYPE_GROUP){
        return;
    }
    EaseAtMessageHelper.get().addAtUser(username);
    EaseUser user = EaseUserUtils.getUserInfo(username);
    if (user != null){
        username = user.getNick();
    }
    if(autoAddAtSymbol)
        inputMenu.insertText("@" + username + " ");
    else
        inputMenu.insertText(username + " ");
}
 
Example #15
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
protected void onConversationInit(){
    // 获取当前conversation对象
    
    conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    // 把此会话的未读数置为0
    conversation.markAllMessagesAsRead();
    // 初始化db时,每个conversation加载数目是getChatOptions().getNumberOfMessagesLoaded
    // 这个数目如果比用户期望进入会话界面时显示的个数不一样,就多加载一些
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
        String msgId = null;
        if (msgs != null && msgs.size() > 0) {
            msgId = msgs.get(0).getMsgId();
        }
        conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
    }
    
}
 
Example #16
Source File: EaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
protected void sendMessage(EMMessage message){
    if (message == null) {
        return;
    }
    if(chatFragmentListener != null){
        //设置扩展属性
        chatFragmentListener.onSetMessageAttributes(message);
    }
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == EaseConstant.CHATTYPE_GROUP){
        message.setChatType(ChatType.GroupChat);
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        message.setChatType(ChatType.ChatRoom);
    }
    //发送消息
    EMClient.getInstance().chatManager().sendMessage(message);
    //刷新ui
    if(isMessageListInited) {
        messageList.refreshSelectLast();
    }
}
 
Example #17
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * send @ message, only support group chat message
 * @param content
 */
@SuppressWarnings("ConstantConditions")
private void sendAtMessage(String content){
    if(chatType != EaseConstant.CHATTYPE_GROUP){
        EMLog.e(TAG, "only support group chat message");
        return;
    }
    EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
    EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
    if(EMClient.getInstance().getCurrentUser().equals(group.getOwner()) && EaseAtMessageHelper.get().containsAtAll(content)){
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL);
    }else {
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG,
                EaseAtMessageHelper.get().atListToJsonArray(EaseAtMessageHelper.get().getAtMessageUsernames(content)));
    }
    sendMessage(message);
    
}
 
Example #18
Source File: RecommendGroupDialogActivity.java    From Social with Apache License 2.0 6 votes vote down vote up
private void joinGroup(){
    //OkhttpUtil.joinGroup(handler,group.id, SharedPreferenceUtil.getUserName());
    //直接加入群组
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                //如果群开群是自由加入的,即group.isMembersOnly()为false,直接join
                EMClient.getInstance().groupManager().joinGroup(group.hx_group_id);//需异步处理
                //添加服务器群组成员记录
                OkhttpUtil.joinGroup(handler, group.id,SharedPreferenceUtil.getUserName());
            }catch (HyphenateException e){
                e.printStackTrace();
            }
        }
    }).start();
}
 
Example #19
Source File: EaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 点击清空聊天记录
 * 
 */
protected void emptyHistory() {
    String msg = getResources().getString(R.string.Whether_to_empty_all_chats);
    new EaseAlertDialog(getActivity(),null, msg, null,new AlertDialogUser() {
        
        @Override
        public void onResult(boolean confirmed, Bundle bundle) {
            if(confirmed){
                // 清空会话
            	
                EMClient.getInstance().chatManager().deleteConversation(toChatUsername, true);
                messageList.refresh();
            }
        }
    }, true).show();;
}
 
Example #20
Source File: EaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 点击进入群组详情
 * 
 */
protected void toGroupDetails() {
    if (chatType == EaseConstant.CHATTYPE_GROUP) {
        EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
        if (group == null) {
            Toast.makeText(getActivity(), R.string.gorup_not_found, 0).show();
            return;
        }
        if(chatFragmentListener != null){
            chatFragmentListener.onEnterToChatDetails();
        }
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
    	if(chatFragmentListener != null){
    		chatFragmentListener.onEnterToChatDetails();
    	}
    }
}
 
Example #21
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
protected void onConversationInit(){
    conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    conversation.markAllMessagesAsRead();
    // the number of messages loaded into conversation is getChatOptions().getNumberOfMessagesLoaded
    // you can change this number
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
        String msgId = null;
        if (msgs != null && msgs.size() > 0) {
            msgId = msgs.get(0).getMsgId();
        }
        conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
    }
    
}
 
Example #22
Source File: EaseConversationListFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * load conversation list
 * 
 * @return
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    +    */
protected List<EMConversation> loadConversationList(){
    // get all conversations
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    /**
     * lastMsgTime will change if there is new message during sorting
     * so use synchronized to make sure timestamp of last message won't change.
     */
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #23
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * capture new image
 */
protected void selectPicFromCamera() {
    if (!EaseCommonUtils.isSdcardExist()) {
        Toast.makeText(getActivity(), R.string.sd_card_does_not_exist, Toast.LENGTH_SHORT).show();
        return;
    }

    cameraFile = new File(PathUtil.getInstance().getImagePath(), EMClient.getInstance().getCurrentUser()
            + System.currentTimeMillis() + ".jpg");
    //noinspection ResultOfMethodCallIgnored
    cameraFile.getParentFile().mkdirs();
    startActivityForResult(
            new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)),
            REQUEST_CODE_CAMERA);
}
 
Example #24
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
protected void onChatRoomViewCreation() {
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", "Joining......");
    EMClient.getInstance().chatroomManager().joinChatRoom(toChatUsername, new EMValueCallBack<EMChatRoom>() {

        @Override
        public void onSuccess(final EMChatRoom value) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(getActivity().isFinishing() || !toChatUsername.equals(value.getId()))
                        return;
                    pd.dismiss();
                    EMChatRoom room = EMClient.getInstance().chatroomManager().getChatRoom(toChatUsername);
                    if (room != null) {
                        titleBar.setTitle(room.getName());
                    } else {
                        titleBar.setTitle(toChatUsername);
                    }
                    EMLog.d(TAG, "join room success : " + room.getName());
                    addChatRoomChangeListenr();
                    onConversationInit();
                    onMessageListInit();
                }
            });
        }

        @Override
        public void onError(final int error, String errorMsg) {
            // TODO Auto-generated method stub
            EMLog.d(TAG, "join room failure : " + error);
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    pd.dismiss();
                }
            });
            getActivity().finish();
        }
    });
}
 
Example #25
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
public void onBackPressed() {
    if (inputMenu.onBackPressed()) {
        getActivity().finish();
        if (chatType == EaseConstant.CHATTYPE_CHATROOM) {
        	EMClient.getInstance().chatroomManager().leaveChatRoom(toChatUsername);
        }
    }
}
 
Example #26
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void onStop() {
    super.onStop();
    // unregister this event listener when this activity enters the
    // background
    EMClient.getInstance().chatManager().removeMessageListener(msgListener);

    // 把此activity 从foreground activity 列表里移除
    EaseUI.getInstance().popActivity(getActivity());
}
 
Example #27
Source File: EaseContactListFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * move user to blacklist
 */
protected void moveToBlacklist(final String username){
    final ProgressDialog pd = new ProgressDialog(getActivity());
    String st1 = getResources().getString(R.string.Is_moved_into_blacklist);
    final String st2 = getResources().getString(R.string.Move_into_blacklist_success);
    final String st3 = getResources().getString(R.string.Move_into_blacklist_failure);
    pd.setMessage(st1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                //move to blacklist
                EMClient.getInstance().contactManager().addUserToBlackList(username,false);
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st2, Toast.LENGTH_SHORT).show();
                        refresh();
                    }
                });
            } catch (HyphenateException e) {
                e.printStackTrace();
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st3, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();
    
}
 
Example #28
Source File: MainActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    loadMenuUI();
    EMClient.getInstance().chatManager().addMessageListener(emMessageListener);
    action_messageBadge.setBadgeCount(NotificationDataModel.unRead);
    int count = getUnreadMsgCountTotal();
    registerReceiver(notifyNumChangedReceiver,new IntentFilter(NotificationDataModel.intentFormMainUpDateNotiyNumTag));
}
 
Example #29
Source File: ChatListActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
protected List<EMConversation> loadConversationList(){
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                //if(conversation.getType() != EMConversationType.ChatRoom){
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
                //}
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #30
Source File: HuanXinHelper.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 退出登录
 * 
 * @param unbindDeviceToken
 *            是否解绑设备token(使用GCM才有)
 * @param callback
 *            callback
 */
public void logout(boolean unbindDeviceToken, final EMCallBack callback) {
	Log.d(TAG, "logout: " + unbindDeviceToken);
	EMClient.getInstance().logout(unbindDeviceToken, new EMCallBack() {

		@Override
		public void onSuccess() {
			Log.d(TAG, "logout: onSuccess");
		    reset();
			if (callback != null) {
				callback.onSuccess();
			}

		}

		@Override
		public void onProgress(int progress, String status) {
			if (callback != null) {
				callback.onProgress(progress, status);
			}
		}

		@Override
		public void onError(int code, String error) {
			Log.d(TAG, "logout: onSuccess");
               reset();
			if (callback != null) {
				callback.onError(code, error);
			}
		}
	});
}