/**
   * Receive a new SIP session invitation
   *
   * @param intent Resolved intent
   * @param session SIP session
   */
  public void receiveSipSessionInvitation(Intent intent, GenericSipSession session) {
    // Add session in the list
    MultimediaSessionImpl sessionApi = new MultimediaSessionImpl(session);
    MultimediaSessionServiceImpl.addSipSession(sessionApi);

    // Broadcast intent related to the received invitation
    String number = PhoneUtils.extractNumberFromUri(session.getRemoteContact());
    intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
    intent.putExtra(MultimediaSessionIntent.EXTRA_CONTACT, number);
    intent.putExtra(MultimediaSessionIntent.EXTRA_DISPLAY_NAME, session.getRemoteDisplayName());
    intent.putExtra(MultimediaSessionIntent.EXTRA_SESSION_ID, session.getSessionID());

    // Broadcast intent related to the received invitation
    AndroidFactory.getApplicationContext().sendBroadcast(intent);
  }
  /**
   * Initiates a new multimedia session for real time messaging with a remote contact and for a
   * given service. The messages exchanged in real time during the session may be from any type. The
   * parameter contact supports the following formats: MSISDN in national or international format,
   * SIP address, SIP-URI or Tel-URI. If the format of the contact is not supported an exception is
   * thrown.
   *
   * @param serviceId Service ID
   * @param contact Contact
   * @param listener Multimedia session event listener
   * @return Multimedia session
   * @throws ServerApiException
   */
  public IMultimediaSession initiateSession(
      String serviceId, String contact, IMultimediaSessionListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a multimedia session with " + contact);
    }

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Initiate a new session
      String featureTag =
          FeatureTags.FEATURE_RCSE
              + "=\""
              + FeatureTags.FEATURE_RCSE_EXTENSION
              + "."
              + serviceId
              + "\"";
      final GenericSipSession session =
          Core.getInstance().getSipService().initiateSession(contact, featureTag);

      // Add session listener
      MultimediaSessionImpl sessionApi = new MultimediaSessionImpl(session);
      sessionApi.addEventListener(listener);

      // Start the session
      Thread t =
          new Thread() {
            public void run() {
              session.startSession();
            }
          };
      t.start();

      // Add session in the list
      MultimediaSessionServiceImpl.addSipSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }