Search in sources :

Example 1 with OnMessageNotifyListener

use of com.easemob.chat.OnMessageNotifyListener in project wechat by motianhuo.

the class App method initEMChat.

private void initEMChat() {
    int pid = android.os.Process.myPid();
    String processAppName = getAppName(pid);
    if (processAppName == null || !processAppName.equalsIgnoreCase("com.juns.wechat")) {
        return;
    }
    EMChatOptions options = EMChatManager.getInstance().getChatOptions();
    // 获取到EMChatOptions对象
    // 设置自定义的文字提示
    options.setNotifyText(new OnMessageNotifyListener() {

        @Override
        public String onNewMessageNotify(EMMessage message) {
            return "你的好友发来了一条消息哦";
        }

        @Override
        public String onLatestMessageNotify(EMMessage message, int fromUsersNum, int messageNum) {
            return fromUsersNum + "个好友,发来了" + messageNum + "条消息";
        }

        @Override
        public String onSetNotificationTitle(EMMessage arg0) {
            return null;
        }

        @Override
        public int onSetSmallIcon(EMMessage arg0) {
            return 0;
        }
    });
    options.setOnNotificationClickListener(new OnNotificationClickListener() {

        @Override
        public Intent onNotificationClick(EMMessage message) {
            Intent intent = new Intent(_context, MainActivity.class);
            ChatType chatType = message.getChatType();
            if (chatType == ChatType.Chat) {
                // 单聊信息
                intent.putExtra("userId", message.getFrom());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_SINGLE);
            } else {
                // 群聊信息
                // message.getTo()为群聊id
                intent.putExtra("groupId", message.getTo());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
            }
            return intent;
        }
    });
// IntentFilter callFilter = new
// IntentFilter(EMChatManager.getInstance()
// .getIncomingCallBroadcastAction());
// registerReceiver(new CallReceiver(), callFilter);
}
Also used : ChatType(com.easemob.chat.EMMessage.ChatType) OnMessageNotifyListener(com.easemob.chat.OnMessageNotifyListener) OnNotificationClickListener(com.easemob.chat.OnNotificationClickListener) Intent(android.content.Intent) EMChatOptions(com.easemob.chat.EMChatOptions) EMMessage(com.easemob.chat.EMMessage)

Aggregations

Intent (android.content.Intent)1 EMChatOptions (com.easemob.chat.EMChatOptions)1 EMMessage (com.easemob.chat.EMMessage)1 ChatType (com.easemob.chat.EMMessage.ChatType)1 OnMessageNotifyListener (com.easemob.chat.OnMessageNotifyListener)1 OnNotificationClickListener (com.easemob.chat.OnNotificationClickListener)1