2013-08-11 18 views
7

Tak więc, od pewnego czasu koduję tę aplikację Android Sip przy użyciu biblioteki Androids Sip, ale nie mogę uruchomić rejestracji . Obecnie daje mi następujący błąd, gdy zadzwonić SipManager.register(): android.net.sip.SipException: SipService.createSession() returns null.Android SipManager: android.net.sip.SipException: SipService.createSession() zwraca wartość null

Mój kod:

public static void Register(final String username, final String password, final String domain, final String cbf) 
     throws ParseException, SipException { 

    Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register"); 
    /* 
    * Luodaan SIP-profiili 
    */ 
    SipProfile.Builder builder = new SipProfile.Builder(username, domain); 
    builder.setPassword(password); 
    //builder.setProtocol("TCP"); 
    //builder.setPort(5060); 
    builder.setAutoRegistration(false); 
    _sipprofile = builder.build(); 

    Intent intent = new Intent(); 
    intent.setAction("android.jahtipuhelin.INCOMING_CALL"); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, intent, Intent.FILL_IN_DATA); 
    _sipmanager.open(_sipprofile, pendingIntent, new SipRegistrationListener() { 
     @Override 
     public void onRegistering(String s) { 
      Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 0"); 

     } 

     @Override 
     public void onRegistrationDone(String s, long l) { 
      Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 1"); 

      try { 
       _sipmanager.register(_sipprofile, 30, null); 
       _sipmanager.setRegistrationListener(_sipprofile.getUriString(), new JPSipRegistrationListener(_class, cbf)); 
      } catch (SipException e) { 
       Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage()); 
       e.printStackTrace(); 
      } 
     } 

     @Override 
     public void onRegistrationFailed(String s, int i, String s2) { 
      Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - testi 2"); 
      Log.d(MainActivity.LOGTAG, s2); 

      try { 

       _sipmanager.register(_sipprofile, 30, null); 
       _sipmanager.setRegistrationListener(_sipprofile.getUriString(), new JPSipRegistrationListener(_class, cbf)); 
      } catch (SipException e) { 
       Log.e(MainActivity.LOGTAG,e.getClass().toString()+ ": "+ e.getMessage()); 
       e.printStackTrace(); 
      } 
     } 
    });//*/ 

    Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.Register - 2"); 
} 


private static class JPSipRegistrationListener implements SipRegistrationListener { 
    private MainActivity _parent; 
    private String _callBack; 

    public JPSipRegistrationListener(MainActivity ma, String callBack) { 
     this._parent = ma; 
     this._callBack = callBack; 
    } 

    @Override 
    public void onRegistering(String localProfileUri) { 
     Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistering"); 
     _parent.callSub(_callBack, REGISTERING, 0, ""); 
    } 

    @Override 
    public void onRegistrationDone(String localProfileUri, long expiryTime) { 
     Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationDone"); 

     _parent.callSub(_callBack, REGISTRATION_DONE, 0, ""); 
    } 

    @Override 
    public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) { 
     Log.d(MainActivity.LOGTAG, "testi: JahtipuhelinSipManager.onRegistrationFailed"); 

     Log.e(MainActivity.LOGTAG, "Virhe Sip-rekisteröinnissä: "+errorCode+": "+errorMessage); 
     if (errorCode == -10) { 
      return; 
     } 
     _parent.callSub(_callBack, REGISTRATION_FAILED, errorCode, errorMessage); 
    } 

} 

Bieg, który daje następujący wynik:

08-11 18:50:58.276 24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register 
08-11 18:50:58.436 24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - testi 2 
08-11 18:50:58.436 24449-24465/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: registration not running 
08-11 18:50:58.446 24449-24449/fi.hieta.aatu.android.jahtipuhelin D/fi.hieta.aatu.android.jahtipuhelin: testi: JahtipuhelinSipManager.Register - 2 
08-11 18:50:58.666 24449-24465/fi.hieta.aatu.android.jahtipuhelin E/fi.hieta.aatu.android.jahtipuhelin: class android.net.sip.SipException: SipService.createSession() returns null 

Czy ktoś wie, co robię źle tutaj? Próbuję też ręcznie zarejestrować profil SIP, a nie przy użyciu autorejestracji. (btw moje pierwsze pytanie na stackoverflow, więc proszę bądźcie łagodni :))

+0

Czy próbujesz zarejestrować się przy użyciu mobilnego połączenia transmisji danych ????? spróbuj z wifi –

Odpowiedz

4

Aktualizacja: Tym rozwiązaniem nie było żadnego wyjątku, ale nie mogłem odebrać żadnych połączeń.

Właśnie znalazłem rozwiązanie. Musisz zadzwonić, zanim zadzwonisz do rejestru. Ponadto nie używaj detektora z otwartym (SipDemo tak mówi, nie wiesz dlaczego), ale zarejestruj go po rejestracji (działa dla mnie).

Więc mój kod jest:

manager.open(localProfile, pendingIntent, null); 

manager.register(localProfile, 20, listener); 

manager.setRegistrationListener(localProfile.getUriString(), listener); 
+1

Nie potrzebowałem setRegistrationListener i działało na moim Nexusie 4 na Androidzie 4.4.4 - ale na Nexusie 5 z Androidem 4.4.4 nadal otrzymuję SipService.createSession() zwraca null. – Toubey

5

Nie wydaje się być co najmniej kolejne dziwactwo powodując tym samym kodem błędu. Jeśli zdarzy ci się, że masz wstępnie zdefiniowane konto z tym samym identyfikatorem URI żądania w telefonie, ten drugi, który próbujesz utworzyć w swojej aplikacji, nie działa w ten sposób. Należy zauważyć, że dzieje się tak nawet wtedy, gdy to konto nie jest ustawione dla połączeń przychodzących (= SIP Register in the backend). Mam nadzieję, że zespół Androida naprawi ten błąd lub przynajmniej rzuci znaczący błąd.

Powiązane problemy