android - 无法让 SipDemo 注册 sip 语音通话

标签 android

这几天我在尝试注册 sip 调用时遇到了问题。下面是我的代码,有人能告诉我 sip 注册中的问题是什么吗?

public class SipRegistration extends Activity {

    public String sipAddress;
    public SipManager manager = null;
    public SipProfile profile = null;
    public SipAudioCall call = null;
    private EditText user, pass, domaine;
    // private SipAudioCall.Listener listener;
    protected static final String TAG = null;
    private Button register;
    private SipRegistrationListener listener;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        user = (EditText) findViewById(R.id.main_edtUser);
        pass = (EditText) findViewById(R.id.main_edtPassword);
        domaine = (EditText) findViewById(R.id.main_edtDomain);
        register = (Button) findViewById(R.id.main_btnRegister);

        register.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                initializeLocalProfile();

            }
        });
    }


    /**
     * Logs you into your SIP provider, registering this device as the location
     * to send SIP calls to for your SIP address.
     * 
     * @return
     */
    public boolean initializeLocalProfile() {
        if (manager == null) {
            manager = SipManager.newInstance(this);
        }

        Log.e("On build profile.......", "");



        String username = user.getText().toString();
        String domain = domaine.getText().toString();
        String password = pass.getText().toString();

        if (username.length() == 0 || domain.length() == 0
                || password.length() == 0) {
            return true;
        }
        Log.e("@@@@@@@@", "username \n" + username);
        Log.e("@@@@@@@@@", "domain \n" + domain);
        Log.e("@@@@@@@", "password \n" + password);

        try {
            SipProfile.Builder builder = new SipProfile.Builder(username,
                    domain);
            builder.setPassword(password);
            profile = builder.build();
            Log.e("profile Password", "" + builder.build());

            // Intent i = new Intent();
            // i.setAction("android.SipDemo.INCOMING_CALL");
            // PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,
            // Intent.FILL_IN_DATA);
            // manager.open(profile, pi, null);
             manager.open(profile);
            Log.e("Profile:", "" + profile);
            // Log.e("Intent:", "" + pi);

            // Log.e("Listner:", "" + listener);
            listener = new SipRegistrationListener() {

                public void onRegistering(String localProfileUri) {
                    // TODO Auto-generated method stub
                    updateStatus("Registering with SIP Server...");
                    Log.e("Registration Running..........", "");
                    try {
                        manager.register(profile, 3000, listener);
                    } catch (SipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                public void onRegistrationDone(String localProfileUri,
                        long expiryTime) {
                    // TODO Auto-generated method stub

                    updateStatus("Ready");
                    Log.e("Registration Done..........", "");
                }

                public void onRegistrationFailed(String localProfileUri,
                        int errorCode, String errorMessage) {
                    // TODO Auto-generated method stub

                    updateStatus("Registration failed.  Please check settings.");
                    Log.e("Registration failed..........", "");

                }

            };

            if (manager.isRegistered(profile.getUriString())) {
                Log.e("SipManager is ready for calls", "");
                return true;
            } else
                return false;

        } catch (Exception ex) {

            Log.e("---Error-- initializeProfile: " + ex.getMessage(), "");
            return false;

        }

    }

    // This listener must be added AFTER manager.open is called,
    // Otherwise the methods aren't guaranteed to fire.

    public void updateStatus(final String status) {
        // Be a good citizen. Make sure UI changes fire on the UI thread.
        this.runOnUiThread(new Runnable() {
            public void run() {
                TextView labelView = (TextView) findViewById(R.id.main_sipLabel);
                labelView.setText(status);
                Log.e("Registration Running..........", "");
            }
        });
    }
}

最佳答案

使用

将端口号更改为8891
Sipmanger.port(); 

Sip 演示在真实设备 (2.3) 或更高版本上实际运行。 确保在 list 文件中添加权限。

关于android - 无法让 SipDemo 注册 sip 语音通话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789343/

相关文章:

java - Haxe:构建到 android 目标时崩溃

android - 使用布局权重获取 TextView 集的高度和宽度?

android - 如何在 Jetpack Compose 中强制某些屏幕的方向?

android - 是否可以手动激活移动网络?

android - 如何访问菜单项?

java - JSoup 是将网站变成原生 Android 应用程序的最佳选择吗

android - 将 View 动态添加到 fragment 内的 ScrollView

android - 媒体播放器 : Should have subtitle controller already set: KitKat

android - 我应该使用哪种类型的数据库?

android - 在亚马逊应用商店发布安卓应用