Esempio n. 1
0
  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);
  }
Esempio n. 2
0
  /**
   * please make sure you have to get EMChatOptions by following method and set related options
   * EMChatOptions options = EMChatManager.getInstance().getChatOptions();
   */
  protected void initHXOptions() {
    Log.d(TAG, "init HuanXin Options");

    // 获取到EMChatOptions对象
    EMChatOptions options = EMChatManager.getInstance().getChatOptions();
    // 默认添加好友时,是不需要验证的,改成需要验证
    options.setAcceptInvitationAlways(false);
    // 设置收到消息是否有新消息通知,默认为true
    options.setShowNotificationInBackgroud(SharedUtils.getSettingMsgNotification());
    // 设置收到消息是否有声音提示,默认为true
    options.setNoticeBySound(SharedUtils.getSettingMsgSound());
    // 设置收到消息是否震动 默认为true
    options.setNoticedByVibrate(SharedUtils.getSettingMsgVibrate());
    // 设置语音消息播放是否设置为扬声器播放 默认为true
    options.setUseSpeaker(true);
    // 设置notification消息点击时,跳转的intent为自定义的intent
    options.setOnNotificationClickListener(getNotificationClickListener());
    options.setNotifyText(getMessageNotifyListener());
  }
Esempio n. 3
0
  /**
   * please make sure you have to get EMChatOptions by following method and set related options
   * EMChatOptions options = EMChatManager.getInstance().getChatOptions();
   */
  protected void initHXOptions() {

    // 获取到EMChatOptions对象
    EMChatOptions options = EMChatManager.getInstance().getChatOptions();
    // 默认添加好友时,是不需要验证的,改成需要验证
    options.setAcceptInvitationAlways(hxModel.getAcceptInvitationAlways());
    // 默认环信是不维护好友关系列表的,如果app依赖环信的好友关系,把这个属性设置为true
    options.setUseRoster(hxModel.getUseHXRoster());
    // 设置收到消息是否有新消息通知(声音和震动提示),默认为true
    options.setNotifyBySoundAndVibrate(hxModel.getSettingMsgNotification());
    // 设置收到消息是否有声音提示,默认为true
    options.setNoticeBySound(hxModel.getSettingMsgSound());
    // 设置收到消息是否震动 默认为true
    options.setNoticedByVibrate(hxModel.getSettingMsgVibrate());
    // 设置语音消息播放是否设置为扬声器播放 默认为true
    options.setUseSpeaker(hxModel.getSettingMsgSpeaker());
    // 设置是否需要已读回执
    options.setRequireAck(hxModel.getRequireReadAck());
    // 设置是否需要已送达回执
    options.setRequireDeliveryAck(hxModel.getRequireDeliveryAck());
    // 设置notification消息点击时,跳转的intent为自定义的intent
    options.setOnNotificationClickListener(getNotificationClickListener());
    options.setNotifyText(getMessageNotifyListener());
  }