Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

sip

So, I've been coding this Android Sip application using Androids Sip library for some time, but i can't get the registration to work. Currently it gives me the following error when i call SipManager.register() : android.net.sip.SipException: SipService.createSession() returns null.

My code:

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

}

Running that gives the following output:

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

Does anyone know what i am doing wrong here? Also, I'm trying to manually register the sip profile, not by using autoregistration. (btw my first question on stackoverflow, so please be gentle :))

like image 876
Aatu Hieta Avatar asked Aug 11 '13 16:08

Aatu Hieta


2 Answers

There seems to be at least another quirk resulting in the same error code. If you happen to have a pre-defined account with the same request URI on your phone the second one you are trying to create in your app fails this way. Note that this happens even if that account is not set for incoming calls (= SIP Register in the backend). I hope the Android team will fix this bug or at least throw a meaningful error.

like image 76
Stoffe Avatar answered Nov 09 '22 02:11

Stoffe


Update: With that solution the exception was gone but I could not recieve any calls.

I just found the solution. You have to call open before you call register. In addition don't use a listener with open (the SipDemo says so, not sure why) but register it after registering (works for me).

So my code is:

manager.open(localProfile, pendingIntent, null);

manager.register(localProfile, 20, listener);

manager.setRegistrationListener(localProfile.getUriString(), listener);
like image 32
Hannes Niederhausen Avatar answered Nov 09 '22 01:11

Hannes Niederhausen