Java Code Examples for com.hyphenate.chat.EMMessage#getFrom()

The following examples show how to use com.hyphenate.chat.EMMessage#getFrom() . 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: EaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {

    for (EMMessage message : messages) {
              String username = null;
              // 群组消息
              if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
                  username = message.getTo();
              } else {
                  // 单聊消息
                  username = message.getFrom();
              }
  
              // 如果是当前会话的消息,刷新聊天页面
              if (username.equals(toChatUsername)) {
                  messageList.refreshSelectLast();
                  // 声音和震动提示有新消息
                  EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
              } else {
                  // 如果消息不是和当前聊天ID的消息
                  EaseUI.getInstance().getNotifier().onNewMsg(message);
              }
    }
}
 
Example 2
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {
    for (EMMessage message : messages) {
        String username = null;
        // group message
        if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
            username = message.getTo();
        } else {
            // single chat message
            username = message.getFrom();
        }

        // if the message is for current conversation
        if (username.equals(toChatUsername) || message.getTo().equals(toChatUsername)) {
            messageList.refreshSelectLast();
            EaseUI.getInstance().getNotifier().vibrateAndPlayTone(message);
        } else {
            EaseUI.getInstance().getNotifier().onNewMsg(message);
        }
    }
}
 
Example 3
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {

    for (EMMessage message : messages) {
              String username = null;
              // 群组消息
              if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
                  username = message.getTo();
              } else {
                  // 单聊消息
                  username = message.getFrom();
              }
  
              // 如果是当前会话的消息,刷新聊天页面
              if (username.equals(toChatUsername)) {
                  messageList.refreshSelectLast();
                  // 声音和震动提示有新消息
                  EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
              } else {
                  // 如果消息不是和当前聊天ID的消息
                  EaseUI.getInstance().getNotifier().onNewMsg(message);
              }
    }
}
 
Example 4
Source File: NewCallRecordEventBean.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
public NewCallRecordEventBean(EMMessage message)
{
    this.message = message;
    if (message.direct() == EMMessage.Direct.SEND)
        this.conId = message.getTo();
    else
        this.conId = message.getFrom();
}
 
Example 5
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {
    Log.d("MyEaseChatFragmetn", "新消息!!!!!!!!!");
    for (EMMessage message : messages) {
        String username = null;
        // 群组消息
        if (message.getChatType() == EMMessage.ChatType.GroupChat || message.getChatType() == EMMessage.ChatType.ChatRoom) {
            username = message.getTo();
        } else {
            // 单聊消息
            username = message.getFrom();
        }

        // 如果是当前会话的消息,刷新聊天页面
        Log.d("MyEaseChatFragment", "username = "  + username + "\n" + "tochatUser = "+ toChatUsername);
        if (username.equals(toChatUsername)) {
            messageList.refreshSelectLast();
        } else {
            // 如果消息不是和当前聊天ID的消息
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext());
            builder.setTicker("新消息");
            builder.setContentTitle(SharedPreferenceUtil.getUserNickname(message.getUserName()));
            builder.setContentText("发来消息,请查看");
            builder.setSmallIcon(R.mipmap.logo);
            builder.setLights(0xff00ff00, 300, 1000);
            //默认系统设置
            builder.setDefaults(NotificationCompat.DEFAULT_ALL);

            //builder.setContentInfo("This is content info");
            builder.setAutoCancel(true);
            Intent intent = new Intent(getContext(), ChatActivity.class);
            intent.putExtra("friend_id", messages.get(0).getUserName());
            PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(pendingIntent);
            NotificationManager notificationManager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(4, builder.build());

            //EaseUI.getInstance().getNotifier().viberateAndPlayTone(messages.get(0));
            //应用在后台,通知栏提示新消息
            if(!EaseUI.getInstance().hasForegroundActivies()){
            }

        }
    }
}