2016-07-13 6 views
1

Ich arbeite an einfachen SIP-Client Android App. Wenn ich versuche, sipProfile auf Server zu registrieren, bekomme ich errorCode = -9 und errorMessage= 0.Android SIP Registrierung fehlgeschlagen mit Fehler "IN_PROGRESS"

Hier sind meine Aktivität:

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()); 
} 

Und meine Berechtigungen:

<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" /> 

Wenn ich mit folgendem Code versuchen:

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); 
      } 
     }); 

ich SipException:

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

FIXED

Es sieht aus wie eine der SIP-Sitzungen wurde auf dem Gerät eingefroren. Nach physischem Neustart bekam ich meine Anmeldung

+0

Verwandte: [diese] (http://stackoverflow.com/questions/20101938/sipaudiocall -ohne-Registrierung-a-local-sipprofile), [dies] (http://stackoverflow.com/questions/18174067/android-sipmanager-android-net-sip-sipexception-sipservice-createseces-ret) und [dies] (http://stackoverflow.com/questions/24077623/android-sipprofile-uri-udp-port-error). – Sufian

+0

@Sufian, Danke, ich habe diese Fragen beobachtet, aber die Lösung nicht gefunden –

+1

Es wird dringend empfohlen, es jetzt zu tun. Aktualisieren Sie Ihre Frage und erwähnen Sie, dass Sie die Lösungen in diesen Fragen ausprobiert haben und auch angeben, was passiert ist oder nicht. – Sufian

Antwort

0

Falls diese Fehler Sie schließen lokales Profil benötigen, und wiederholen Sie erstellen Sitzung

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(); 
         } 
        } 

       } 
      }); 
Verwandte Themen