2016-07-13 3 views
1

Я работаю над простым SIP-клиентским Android-приложением.Ошибка регистрации sip в Android с ошибкой «IN_PROGRESS»

Но когда я пытаюсь зарегистрировать sipProfile на сервере, я получаю errorCode = -9 и errorMessage= 0.

Вот моя активность:

public SipManager sipManager; 
private SipProfile sipProfile; 

// here is the data, I've just erased it 
private String USERNAME = ""; 
private String AUTHUSERNAME = ""; 
private String DOMAIN = ""; 
private String PASSWORD = ""; 
private int PORT = 5060; 

public SipAudioCall call = null; 
public String sipAddress = null; 

private Button btnRegister, btnCloseProfile; 
private TextView tvStatus; 
public IncomingCallReceiver callReceiver; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    btnRegister = (Button) findViewById(R.id.btnRegister); 
    tvStatus = (TextView) findViewById(R.id.tvStatus); 
    btnCloseProfile = (Button) findViewById(R.id.btnCloseProfile); 

    btnRegister.setOnClickListener(register); 
    btnCloseProfile.setOnClickListener(closeProfile); 

    IntentFilter filter = new IntentFilter(); 
    filter.addAction("android.SipDemo.INCOMING_CALL"); 
    callReceiver = new IncomingCallReceiver(); 
    this.registerReceiver(callReceiver, filter); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

} 

View.OnClickListener closeProfile = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     closeLocalProfile(); 
    } 
}; 
View.OnClickListener register = new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     initializeManager(); 
    } 
}; 

void initializeManager(){ 
    if(sipManager == null) { 
     sipManager = SipManager.newInstance(this); 
    } 

    initializeLocalProfile(); 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
    initializeManager(); 
} 

public void initializeLocalProfile(){ 
    if (sipManager == null){ 
     return; 
    } 

    if (sipProfile != null){ 
     closeLocalProfile(); 
    } 

    try { 
     SipProfile.Builder builder = new SipProfile.Builder(USERNAME, DOMAIN); 
     builder.setPassword(PASSWORD); 
     builder.setAuthUserName(AUTHUSERNAME); 
     sipProfile = builder.build(); 

     Intent intent = new Intent(); 
     intent.setAction("ru.tenet.apdu.INCOMING_CALL"); 
     PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA); 
     sipManager.open(sipProfile, pi, null); 

     sipManager.setRegistrationListener(sipProfile.getUriString(), new SipRegistrationListener() { 
      @Override 
      public void onRegistering(String localProfileUri) { 
       updateStatus("Registering with SIP Server..."); 
      } 

      @Override 
      public void onRegistrationDone(String localProfileUri, long expiryTime) { 
       updateStatus("Ready"); 
      } 

      @Override 
      public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) { 
       updateStatus("Registration failed with error:\n" + SipErrorCode.toString(errorCode) +"\n"+errorMessage); 
      } 
     }); 

    } 
    catch (SipException e){ 
     e.printStackTrace(); 
     updateStatus("SipException"); 
    } catch (ParseException e) { 
     e.printStackTrace(); 
     updateStatus("ParseException"); 
    } 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    if (call != null) { 
     call.close(); 
    } 

    closeLocalProfile(); 
    if (callReceiver != null) { 
     this.unregisterReceiver(callReceiver); 
    } 
} 

public void closeLocalProfile() { 
    if (sipManager == null) { 
     return; 
    } 
    try { 
     if (sipProfile != null) { 
      sipManager.close(sipProfile.getUriString()); 
     } 
    } catch (Exception ee) { 
     Log.d("StatusWindow/onDestroy", "Failed to close local profile.", ee); 
    } 
} 

void updateStatus(final String status){ 
    Log.d("mylog","status = " +status); 
    runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      tvStatus.setText(status); 
     } 
    }); 
} 

public void updateStatus(SipAudioCall call) { 
    String useName = call.getPeerProfile().getDisplayName(); 
    if(useName == null) { 
     useName = call.getPeerProfile().getUserName(); 
    } 
    updateStatus(useName + "@" + call.getPeerProfile().getSipDomain()); 
} 

И мои права:

<uses-permission android:name="android.permission.USE_SIP"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 

Если я пытаюсь с помощью следующего кода:

sipManager.open(sipProfile, pi, null); 
sipManager.register(sipProfile, 20, new SipRegistrationListener() { 
      @Override 
      public void onRegistering(String localProfileUri) { 
       updateStatus("Registering with SIP Server..."); 
      } 

      @Override 
      public void onRegistrationDone(String localProfileUri, long expiryTime) { 
       updateStatus("Ready"); 
      } 

      @Override 
      public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) { 
       updateStatus("Registration failed with error:\n" + SipErrorCode.toString(errorCode) +"\n"+errorMessage); 
      } 
     }); 

я SipException:

android.net.sip.SipException: SipService.createSession() returns null 

FIXED

Это выглядит как один из потягивать сессий были заморожены на устройстве. После физической перезагрузки я получил мою регистрацию

+0

Связанные: [это] (http://stackoverflow.com/questions/20101938/sipaudiocall -without-registering-a-local-sipprofile), [это] (http://stackoverflow.com/questions/18174067/android-sipmanager-android-net-sip-sipexception-sipservice-createsession-ret) и [это] (http://stackoverflow.com/questions/24077623/android-sipprofile-uri-udp-port-error). – Sufian

+0

@Sufian, Спасибо, я смотрел эти вопросы, но не нашел там решения –

+1

Настоятельно рекомендуется сделать это сейчас. Обновите свой вопрос и укажите, что вы пробовали решения в этих вопросах, а также выяснили, что произошло или нет. – Sufian

ответ

0

В случае, если это ошибка, которую вы нуждаются в пристальном локальный профиль и повторить создать сеанс

manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() { 
       public void onRegistering(String localProfileUri) { 
        updateStatus("Registering with SIP Server..."); 
       } 

       public void onRegistrationDone(String localProfileUri, long expiryTime) { 
        updateStatus("Ready"); 
       } 

       public void onRegistrationFailed(String localProfileUri, int errorCode, 
               String errorMessage) { 
        if(errorCode == SipErrorCode.IN_PROGRESS) { 
         closeLocalProfile(); 
         try { 
          manager.open(me, pi, null); 
         } catch (SipException e) { 
          e.printStackTrace(); 
         } 
        } 

       } 
      }); 
Смежные вопросы