private static void showNotification(ECMessage msg) { if (checkNeedNotification(msg.getSessionId())) { ECNotificationManager.getInstance().forceCancelNotification(); String lastMsg = ""; if (msg.getType() == ECMessage.Type.TXT) { lastMsg = ((ECTextMessageBody) msg.getBody()).getMessage(); } ECContacts contact = ContactSqlManager.getContact(msg.getForm()); if (contact == null) { return; } ECNotificationManager.getInstance() .showCustomNewMessageNotification( CCPAppManager.getContext(), lastMsg, contact.getNickname(), msg.getSessionId(), msg.getType().ordinal()); } }
@Override public void onReceiveOfflineMessageCompletion() { if (mOfflineMsg == null) { return; } // SDK离线消息拉取完成之后会通过该接口通知应用 // 应用可以在此做类似于Loading框的关闭,Notification通知等等 // 如果已经没有需要同步消息的请求时候,则状态栏开始提醒 ECMessage lastECMessage = mOfflineMsg; try { if (lastECMessage != null && mHistoryMsgCount > 0 && isFirstSync) { showNotification(lastECMessage); // lastECMessage.setSessionId(lastECMessage.getTo().startsWith("G")?lastECMessage.getTo():lastECMessage.getForm()); } } catch (Exception e) { e.printStackTrace(); } isFirstSync = isSyncOffline = false; // 无需要同步的消息 CCPAppManager.getContext().sendBroadcast(new Intent(INTENT_ACTION_SYNC_MESSAGE)); mOfflineMsg = null; }
@Override public void onSendMessageComplete(ECError error, ECMessage message) { if (message == null) { return; } // 处理ECMessage的发送状态 if (message != null) { if (message.getType() == ECMessage.Type.VOICE) { try { DemoUtils.playNotifycationMusic( CCPAppManager.getContext(), "sound/voice_message_sent.mp3"); } catch (IOException e) { e.printStackTrace(); } } IMessageSqlManager.setIMessageSendStatus( message.getMsgId(), message.getMsgStatus().ordinal()); IMessageSqlManager.notifyMsgChanged(message.getSessionId()); if (mOnMessageReportCallback != null) { mOnMessageReportCallback.onMessageReport(error, message); } return; } }
public void getPersonInfo() { LogUtil.d(TAG, "[getPersonInfo] currentVersion :"); final ClientUser clientUser = CCPAppManager.getClientUser(); if (clientUser == null) { return; } LogUtil.d( TAG, "[getPersonInfo] currentVersion :" + clientUser.getpVersion() + " ,ServerVersion: " + mServicePersonVersion); if (clientUser.getpVersion() < mServicePersonVersion) { SDKCoreHelper.getECChatManager() .getPersonInfo( new ECChatManager.OnGetPersonInfoListener() { @Override public void onGetPersonInfoComplete(ECError e, PersonInfo p) { clientUser.setpVersion(p.getVersion()); clientUser.setSex(p.getSex()); clientUser.setUserName(p.getNickName()); if (!TextUtils.isEmpty(p.getBirth())) { clientUser.setBirth(DateUtil.getActiveTimelong(p.getBirth())); } String newVersion = clientUser.toString(); LogUtil.d(TAG, "[getPersonInfo -result] ClientUser :" + newVersion); try { ECPreferences.savePreference( ECPreferenceSettings.SETTINGS_REGIST_AUTO, newVersion, true); } catch (InvalidClassException e1) { e1.printStackTrace(); } } }); } }