Android Sip注册失败,错误为"IN_PROGRESS" [英] Android sip registration failed with error "IN_PROGRESS"

查看:110
本文介绍了Android Sip注册失败,错误为"IN_PROGRESS"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发简单的SIP客户端Android应用.

I am working on simple SIP-client Android app.

但是当我尝试在服务器上注册 sipProfile 时,我得到 errorCode = -9 errorMessage = 0 .

But when I try to register sipProfile on Server, I get errorCode = -9 and 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" />

如果我尝试使用以下代码:

If I try with following code:

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:

I get SipException:

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

已修复

似乎Sip会话之一已在设备上冻结.物理重启后,我得到了注册

It looks like one of the sip sessions has been frozen on device. After physical reboot I got my registration

推荐答案

经过大量搜索并经历了多个stackoverflow答案,并浪费了2天的注册错误,这是您应该考虑完成注册的事情!这些为我工作.如果他们也为您工作,请回复此答案:)

After lot of searching and going through multiple stackoverflow answers and wasting 2 days on registration errors, here are the things that you should consider to get the registration done ! These worked for me. Reply to this answer if they work for you too :)

检查以下代码:

  1. 首先,检查是否已提供所有必需的权限
  2. 使用 open 方法代替注册&关闭而不是取消注册
  3. 在调用open方法之后设置您的 SipRegisterationListener ,在 open 方法中将 null 作为参数传递给侦听器,并调用 sipManager.setRegisterationListener(监听器)来设置监听器.
  4. 您的域不得包含端口号,它应该是简单的服务器域链接;例如 com.google.com
  5. 首先尝试运行应用程序,而不在 SipProfile.Builder 中设置端口号;如果失败,请使用 builder.setPort(xxxx)
  6. 手动添加端口
  7. 尝试更改协议.目前仅 UDP & TCP 是所提及的可用选项,在本文档中
  8. 检查您建立的个人资料uri的格式为 sip:< username> @< domain> .例如,如果用户名是 abcd 而域是 com.google.com ,则 SipProfile uri字符串应为 sip:abcd@com.google.com
  1. First of all, check whether all required permissions are given or not
  2. Use open method instead of register & close instead of unregister
  3. Set your SipRegisterationListener after calling open method, pass null as a parameter in open method for listener and call sipManager.setRegisterationListener(listener) to set the listener.
  4. Your domain must not include port number it should be simple server domain link ; For example com.google.com
  5. First try running the app without setting the port number in SipProfile.Builder ; if that fails, add port manually using builder.setPort(xxxx)
  6. Try changing the protocol. Currently only UDP & TCP are the options available as mentioned in this documentation
  7. Check that your profile uri built is of the format sip:<username>@<domain>. For example if the username is abcd and domain is com.google.com, the SipProfile uri string should be sip:abcd@com.google.com

如果您的Android代码正确,请尝试以下操作:

  1. 正确检查用户名和密码/尝试其他一些用户名和密码.尝试使用其他凭据之前,请关闭现有的SipProfile,直到成功将其关闭.
  2. 从手机中清除 Phone Service 系统应用程序的数据
  3. 还清除您开发的SIP应用程序的数据
  4. 通过 Phone>关闭设备上所有已打开的/现有的SIP帐户.设置>呼叫权限>Sip帐户;
  5. 重新启动手机
  1. Check the username and password properly / try some other username and password. Before trying with other credentials, close the existing SipProfile until is is successfully closed.
  2. Clear data of Phone Service system apps from your phone
  3. Clear data of your developed SIP app also
  4. Close any open / existing SIP accounts on the device from Phone > Settings > Calling Accouts > Sip Accounts;
  5. Reboot your phone

这篇关于Android Sip注册失败,错误为"IN_PROGRESS"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆