Utku
Utku

Reputation: 435

SIP registration failure

I've got a problem with SIP API. I'm following the guide at d.android.com and got a free SIP account from sip2sip.info to test my application. Update: I tried ekiga.net and I also set up a Kamailio server myself but those didn't help too.

Whenever I try to register my profile, it fails with the error message "0". Here is the code:

package com.mysys.mysip;

import java.text.ParseException;

import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
    public SipManager mSipManager = null;
    public SipProfile mSipProfile = null;

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

        if (mSipManager == null) {
            mSipManager = SipManager.newInstance(this);
        }

        Button connectButton = (Button) findViewById(R.id.buttonConnect);
        connectButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                buildProfile();
                if (mSipProfile != null) {
                    openProfile();
                }
            }
        });
    }

    public void buildProfile() {
        try {
            SipProfile.Builder builder = new SipProfile.Builder("censored", "sip2sip.info");
            builder.setPassword("censored");
            mSipProfile = builder.build();
        } catch (ParseException e) {
            Log.e("SipProfile.Builder", "Parse error!");
            e.printStackTrace();
        }
    }

    public void openProfile() {
        Intent intent = new Intent();
        intent.setAction("com.mysys.sip.INCOMING_CALL");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);

        SipRegistrationListener listener = new SipRegistrationListener() {
            @Override
            public void onRegistering(String localProfileUri) {
                Log.i("SIP Registration", "Registering.");
                updateStatus("Registering...");
            }

            @Override
            public void onRegistrationDone(String localProfileUri, long expiryTime) {
                Log.i("SIP Registration", "Done!");
                updateStatus("Registered! Yay!");
            }

            @Override
            public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
                Log.e("SIP Registration", "Failed! URI: " + localProfileUri + " Reason: " + errorMessage);
                updateStatus("Registration failed.");
            }
        };

        try {
            mSipManager.open(mSipProfile, pendingIntent, null);
            mSipManager.setRegistrationListener(mSipProfile.getUriString(), listener);
        } catch (SipException e) {
            e.printStackTrace();
        }
    }

    public void updateStatus(final String status) {
        this.runOnUiThread(new Runnable() {
            public void run() {
                TextView statusView = (TextView) findViewById(R.id.textViewStatus);
                statusView.setText(status);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_settings:
                Intent intent = new Intent(this, SettingsActivity.class);
                startActivity(intent);
        }
        return super.onOptionsItemSelected(item);
    }
}

I reviewed the code twice, compared to Android SDK's own demo but found nothing. I also searched before asking, the only thing related that I found was setting the protocol to TCP but it didn't solve my problem.

Upvotes: 3

Views: 4846

Answers (3)

Sridhar Gonda
Sridhar Gonda

Reputation: 1

builder.setPort(5060);
builder.setProtocol("TCP");
builder.setOutboundProxy("proxy.sipthor.net");
me = builder.build();

Upvotes: 0

Sofien Rahmouni
Sofien Rahmouni

Reputation: 4917

you can try onther free service sip like https://www.linphone.org/eng/linphone/register-a-linphone-account.html and test it , it worked for me by sip account linphone

Upvotes: 4

Seshu Vinay
Seshu Vinay

Reputation: 13588

Did you check whether following functions are returning true:

isVoipSupported() and isApiSupprted(). Also check whether your SIP account is working.

Upvotes: 0

Related Questions