Ejemplo n.º 1
0
  @Override
  public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
      case EventNewMessage:
        {
          EMMessage message = (EMMessage) event.getData();
          String userId = null;
          userId = message.getFrom();

          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(this)
                  .setSmallIcon(getApplicationContext().getApplicationInfo().icon)
                  .setWhen(System.currentTimeMillis())
                  .setContentTitle("有新消息了!")
                  .setContentText("A+")
                  .setAutoCancel(true);
          Intent resultIntent = new Intent(this, ChatActivity.class);
          resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          resultIntent.putExtra("notification", true);
          resultIntent.putExtra("easemobId", userId);
          TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
          stackBuilder.addParentStack(ChatActivity.class);
          stackBuilder.addNextIntent(resultIntent);
          PendingIntent resultPendingIntent =
              stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
          mBuilder.setContentIntent(resultPendingIntent);
          NotificationManager mNotificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          mNotificationManager.notify(0, mBuilder.build());
        }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
      case EventNewMessage: // 普通消息
        {
          EMMessage message = (EMMessage) event.getData();
          try {
            showLogD("MESSAGE " + message.getStringAttribute("groupName"));
          } catch (EaseMobException e) {
            e.printStackTrace();
          }
          // 提示新消息
          HXSDKHelper.getInstance().getNotifier().onNewMsg(message);

          refreshUI();
          break;
        }

      case EventOfflineMessage:
        {
          refreshUI();
          break;
        }

      case EventConversationListChanged:
        {
          refreshUI();
          break;
        }

      default:
        break;
    }
  }
Ejemplo n.º 3
0
  @Override
  public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
      case EventNewMessage: // 普通消息
        {
          EMMessage message = (EMMessage) event.getData();
          runOnUiThread(
              new Runnable() {
                public void run() {
                  updateUnreadLabel();
                }
              });
          // 提示新消息
          // HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
          EventBus.getDefault().post(message);
          break;
        }

      case EventOfflineMessage:
        {
          EMMessage message = (EMMessage) event.getData();
          runOnUiThread(
              new Runnable() {
                public void run() {
                  updateUnreadLabel();
                }
              });
          // 提示新消息
          // HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
          EventBus.getDefault().post(message);
          break;
        }

      case EventConversationListChanged:
        {
          break;
        }

      default:
        break;
    }
  }