使用android的sip进行Android音频通话

2024-03-12

我为客户开发了一个使用 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" />

请帮助我。提前致谢。


也许添加这些

<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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用android的sip进行Android音频通话 的相关文章

随机推荐

  • 如何处理 WAI ARIA role="listbox"

    我有一个选项列表 可以从中选择一个 出于所有意图和目的 HTML
  • 如何将MYSQL查询转换为MSSQL查询

    我有 700 多个 MySQL 查询 现在尝试在 MSSQL 中创建相同的查询集 我想用相同的 MYSQL 生成 MSSQL 查询 有什么方法可以将 MYSQL 查询转换为 MSSQL 查询 由此article http blogs msd
  • 如何从python opencv中的数组读取原始png?

    我正在通过 TCP 将 png 图像从 iPhone 传输到 MacBook MacBook 代码来自http docs python org library socketserver html requesthandler objects
  • log4j编码utf8

    我使用 Java 和 Log4j 我想记录一个带有德语特殊字符的字符串 例如 等 但在我的日志文件中它看起来像这样
  • 如何使用 phpseclib 验证证书是否由公共 CA 签名?

    我需要确保 SMTP 服务器证书由公共证书颁发机构签名 我想使用 phpseclib 或其他一些受信任的库 我相信我可以使用根证书 https curl haxx se docs caextract html从火狐浏览器中提取 有一些自制方
  • Objective C - 自清零弱指针意外行为

    我最近从 Mavericks 升级到 Yosemite 现在我的单元测试失败了 问题归结为指向字符串内容的弱指针中的拼写错误 请看下面的示例代码 NSString value1 NSString value2 weak NSString w
  • 如何在 C 或 C++ 中全局初始化数组?

    我正在尝试这样做 for int k 0 k
  • 如何覆盖 ruby​​ on Rails 4.0.+ 中的默认主键列?

    我已经有一个现有的数据库架构 其中的表以字符串列作为主键 还有一些表以多个列作为键 我想在 Rails 中映射此架构 但我不知道如何覆盖默认主键 由 Rails 框架创建的列 id 您可以像这样覆盖主键 class Book lt Acti
  • 计算数据库中截止日期与今天日期匹配的所有记录

    我需要计算数据库中截止日期与今天日期匹配的所有记录 我发现我应该能够使用 COUNT 和 CURDATE 来做到这一点 但我无法做到正确 SELECT COUNT id FROM tasks WHERE due date CURDATE 从
  • 在VIM中,是否可以在替代子句中使用选定的文本而无需重新输入?

    假设我在视觉模式下选择了一个单词 我想使用 s 对该单词以及文件中该单词的所有其他实例执行替换 有没有办法使用突出显示的文本s
  • Windows 中是否有类似 GREP 的模式匹配实用程序?

    有没有类似的实用工具grep可从 Windows 命令提示符获取 或者是否有第三方工具 有一个命令行工具叫做FINDSTR随所有 Windows NT 级操作系统一起提供 类型FINDSTR 进入命令提示符窗口以获取更多信息 它并不支持所有
  • 如何使用 geom_boxplot(stat = "identity") 模拟带有异常值的 geom_boxplot()

    我想预先计算数据的变量摘要 使用plyr并通过一个quantile函数 然后用geom boxplot stat identity 这非常有效 除了它 a 不将异常值绘制为点以及 b 将 胡须 扩展到所绘制数据的最大值和最小值 Exampl
  • Git 分支命名规则[重复]

    这个问题在这里已经有答案了 当我在 Git 中命名分支时 我总是倾向于以字母开头 mybranch89例如 Git 分支的命名有什么规则吗 例如 我应该始终以字母开头 还是只能使用数字分支名称 例如876 规则是相当复杂 http git
  • 在 TextView 中显示图像

    我希望在 TextView 中显示图像 我的图像保存在 res raw 目录中 我尝试使用 HTML ImageGetter 但找不到相同的完整参考 import android app Activity import android gr
  • 追踪事务为何升级为 DTC

    有什么方法可以准确确定 System Transaction TrasactionScope 升级为 DTC 的原因吗 我们的一个组件遇到了麻烦 该组件似乎升级了交易 而所有其他组件 看起来看似相似 却没有升级 是否提供了有关升级原因以及如
  • 如何在Python中查找字符串中的一个数字?

    我有一个名为 FILE 1 txt 或 FILE 340 txt 的文件 我希望能够从文件名中获取数字 我发现我可以使用 numbers re findall r d s filename 获取包含数字的列表 并使用numbers 0 将数
  • 什么时候应该使用 XS?

    我正在写一篇关于 XS 的演讲 我需要知道社区何时认为适合采用 XS 我可以想到至少三个使用 XS 的理由 您有一个想要在 Perl 5 中访问的 C 库 您有一段代码 它确实会减慢您的程序速度 如果用 C 编写 速度会更快 您需要访问仅在
  • 想在Mysql中为两个不同的数据库编写触发器

    有没有办法在Mysql中的两个不同的数据库上创建触发器 我的要求是这样的 database test1 gt table tmp1 database test2 gt table tmp2 现在我必须在 test1 上使用触发器插入操作发生
  • 错误:没有匹配的函数来调用“Point::Point()”

    因此 我创建了 Point 类 并希望将其用作 Circle 类中构造函数的参数 但出现错误 没有显示类 Point 的默认构造函数 我不知道如何修复它 代码如下所示 class Point private int x y public P
  • 使用android的sip进行Android音频通话

    我为客户开发了一个使用 sip 进行互联网呼叫的应用程序 为此 他向我提供了两个有效的 sip 用户 ID 和密码 我正在使用 SIP API 进行 SIP 实施 客户说呼叫无法进行 当他使用自己的帐户登录时 他没有收到任何有关未接来电的通