【问题标题】:Android audio calls using android's sip使用 android 的 sip 进行 Android 音频通话
【发布时间】:2017-04-30 05:50:57
【问题描述】:

我为客户开发了一个使用 sip 进行互联网通话的应用程序。为此,他为我提供了两个有效的 sip 用户 ID 和密码。我正在使用 SIP API 进行 SIP 实施。客户说通话没有进行。当他使用他的帐户登录时,他没有收到任何关于未接来电的通知。我在代码中找不到任何错误。请帮助我。代码是下面给出。

public class CallActivity extends Activity {
        public String sipAddress = null;
        public SipManager mSipManager = null;
        public SipProfile mSipProfile = null;
        public SipAudioCall call = null;
        Button b1;
        TextView sipadd;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.calling);
            sipAddress = (String) getIntent().getExtras().get("sipAddress");
            b1 = (Button) findViewById(R.id.sipcallbtnend);
            b1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    finish();
                }
            });

            sipadd = (TextView) findViewById(R.id.sipcalltvdialedaddress);

            sipadd.setText(sipAddress);
            b1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (call != null) {
                        call.close();
                    }
                    finish();
                }
            });
            initializeManager();
        }

        @Override
        public void onStart() {
            super.onStart();
            // When we get back from the preference setting Activity, assume
            // settings have changed, and re-login with new auth info.
            initializeManager();
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            if (call != null) {
                call.close();
            }

            closeLocalProfile();

            // if (callReceiver != null) {
            // this.unregisterReceiver(callReceiver);
            // }
        }

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

            initializeLocalProfile();
        }

        public void initializeLocalProfile() {
            if (mSipManager == null) {
                return;
            }

            if (mSipProfile != null) {
                closeLocalProfile();
            }
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(getBaseContext());
            String username = prefs.getString("namePref", "");
            String domain = prefs.getString("domainPref", "");
            String password = prefs.getString("passPref", "");

            if (username.length() == 0 || domain.length() == 0
                    || password.length() == 0) {
                // showDialog(UPDATE_SETTINGS_DIALOG);
                return;
            }

            try {
                SipProfile.Builder builder = new SipProfile.Builder(username,
                        domain);
                builder.setPassword(password);
                builder.setDisplayName(username);
                builder.setAuthUserName(username);
                mSipProfile = builder.build();

                Intent i = new Intent();
                i.setAction("android.SipDemo.INCOMING_CALL");
                PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,
                        Intent.FILL_IN_DATA);
                mSipManager.open(mSipProfile, pi, null);
                //
                //
                // // This listener must be added AFTER manager.open is called,
                // // Otherwise the methods aren't guaranteed to fire.

                mSipManager.setRegistrationListener(mSipProfile.getUriString(),
                        new SipRegistrationListener() {
                            public void onRegistering(String localProfileUri) {
                                // updateStatus("Registering with SIP Server...");
                                Log.d("onRegistering",
                                        "Registering with SIP Server...");
                            }

                            public void onRegistrationDone(String localProfileUri,
                                    long expiryTime) {
                                // updateStatus("Ready");
                                Log.d("onRegistrationDone",
                                        "RegistrationDone..Ready");

                            }

                            public void onRegistrationFailed(
                                    String localProfileUri, int errorCode,
                                    String errorMessage) {
                                // updateStatus("Registration failed.  Please check settings.");
                                Log.d("onRegistrationFailed", "RegistrationFailed");

                            }
                        });
            } catch (ParseException pe) {
                // updateStatus("Connection Error.");
            } catch (SipException se) {
                // updateStatus("Connection error.");
            }

            initiateCall();
        }

        public void closeLocalProfile() {
            if (mSipManager == null) {
                return;
            }
            try {
                if (mSipProfile != null) {
                    mSipManager.close(mSipProfile.getUriString());
                }
            } catch (Exception ee) {
                Log.d("WalkieTalkieActivity/onDestroy",
                        "Failed to close local profile.", ee);
            }
        }

        public void initiateCall() {

            // updateStatus(sipAddress);
            Log.d("nzm", "initiatecall");

            try {
                SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                    // Much of the client's interaction with the SIP Stack will
                    // happen via listeners. Even making an outgoing call, don't
                    // forget to set up a listener to set things up once the call is
                    // established.
                    @Override
                    public void onCallEstablished(SipAudioCall call) {
                        call.startAudio();
                        call.setSpeakerMode(true);
                        call.toggleMute();
                        Log.d("on call established", "on call established");
                        // updateStatus(call);
                    }

                    @Override
                    public void onCallEnded(SipAudioCall call) {
                        // updateStatus("Ready.");
                        // Intent i = new
                        // Intent(getBaseContext(),DialActivity.class);
                        // startActivity(i);
                        finish();
                    }
                };

                call = mSipManager.makeAudioCall(mSipProfile.getUriString(), sipAddress,
                        listener, 3000);
                Log.d("call", "" + call.getState());
            } catch (Exception e) {
                Log.i("WalkieTalkieActivity/InitiateCall",
                        "Error when trying to close manager.", e);
                if (mSipProfile != null) {
                    try {
                        mSipManager.close(mSipProfile.getUriString());
                    } catch (Exception ee) {
                        Log.i("WalkieTalkieActivity/InitiateCall",
                                "Error when trying to close manager.", ee);
                        ee.printStackTrace();
                    }
                }
                if (call != null) {
                    call.close();
                }
            }
        }

    }

清单中的权限如下所示

<uses-permission android:name="android.permission.USE_SIP" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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" />

    <uses-feature android:name="android.hardware.sip.voip" android:required="true" />
    <uses-feature android:name="android.hardware.wifi" android:required="true" />
    <uses-feature android:name="android.hardware.microphone" android:required="true" />

请帮助我。在此先感谢。

【问题讨论】:

  • 嗨,我被分配了使用 sip 作为大学项目的 voip。我面临很多麻烦。你有它的工作吗?如果是,那么您可以将项目发送给我,因为 android 示例无法正常工作。我会很感激的
  • 很抱歉我的应用程序无法正常工作。如果我能找到任何对您有帮助的东西,我会通知您。请将您的邮件 ID 发送到 noufalm786@gmail.com
  • @Noufal 我在使用 SIP 时遇到了一个很糟糕的问题。如果您找到任何解决方案,我将很高兴知道。请看我的问题:stackoverflow.com/questions/25520246/local-voip-call-with-sip

标签: android sip


【解决方案1】:

也许添加这些

<uses-permission android:name="android.permission.CONFIGURE_SIP" />

<uses-feature android:name="android.software.sip" android:required="true" />
<uses-feature android:name="android.software.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />

你用的是android的例子吗?它应该在支持 SIP 的设备上工作。

并在 onCreate 中添加接收者

IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);

【讨论】:

  • 谢谢。我根据您的建议编辑了代码。但仍然无法正常工作。
  • 我得到了应用程序的一些积极响应。我在@override onRingingBack(SipAudioCall 呼叫)中得到了一个日志。但不确定任何最终呼叫者会收到呼叫。哪个 sip 帐户适合测试。
【解决方案2】:

清单中有这个吗?:

<receiver android:name=".IncomingCallReceiver" android:label="Call Receiver"/>

见: https://developer.android.com/guide/topics/connectivity/sip.htmlhttps://android.googlesource.com/platform/development/+/master/samples/SipDemo/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    相关资源
    最近更新 更多