android中Sip音频通话调研结果

        分类:            android移动开发2011-10-19 15:541539人阅读评论(0)收藏举报
[java] view plaincopyprint?
  1. <span style="font-family: Arial, Verdana, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">     首先简单介绍一下sip协议,sip是会话启动协议,主要用于网络多媒体通话。必须是android2.3或其以上版本才可以调用Sip api,并且设备必须支持sip才可以进行sip通话。</span>
     首先简单介绍一下sip协议,sip是会话启动协议,主要用于网络多媒体通话。必须是android2.3或其以上版本才可以调用Sip api,并且设备必须支持sip才可以进行sip通话。

SIP使用的api主要放在android.net.sip中,其中最核心的类为SipManager.java,关系图如下所示:

本地的SipProfile存放在一个xml文件中,主要用于保存sip的username,domain和password,SharedPreference配置文件如下所示:

[html] view plaincopyprint?
  1. <PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android">
  2. <EditTextPreference
  3. android:name="SIP Username"
  4. android:summary="Username for your SIP Account"
  5. android:defaultValue=""
  6. android:title="Enter Username"
  7. android:key="namePref"/>
  8. <EditTextPreference
  9. android:name="SIP Domain"
  10. android:summary="Domain for your SIP Account"
  11. android:defaultValue=""
  12. android:title="Enter Domain"
  13. android:key="domainPref"/>
  14. <EditTextPreference
  15. android:name="SIP Password"
  16. android:summary="Password for your SIP Account"
  17. android:defaultValue=""
  18. android:title="Enter Password"
  19. android:key="passPref"
  20. android:password="true"
  21. />
  22. </PreferenceScreen>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"><EditTextPreferenceandroid:name="SIP Username"android:summary="Username for your SIP Account"android:defaultValue=""android:title="Enter Username"android:key="namePref" /><EditTextPreferenceandroid:name="SIP Domain"android:summary="Domain for your SIP Account"android:defaultValue=""android:title="Enter Domain"android:key="domainPref" /><EditTextPreferenceandroid:name="SIP Password"android:summary="Password for your SIP Account"android:defaultValue=""android:title="Enter Password"android:key="passPref"android:password="true" />
</PreferenceScreen>

更新SharedPreference的代码如下:

[java] view plaincopyprint?
  1. publicvoid updatePreferences() {
  2. Intent settingsActivity = new Intent(getBaseContext(),
  3. SipSettings.class);
  4. startActivity(settingsActivity);
  5. }
public void updatePreferences() {Intent settingsActivity = new Intent(getBaseContext(),SipSettings.class);startActivity(settingsActivity);}

调用updatePreferences()方法会有如下的效果图显示:

[java] view plaincopyprint?
  1. <img alt="" src="https://img-blog.csdnimg.cn/2022010703245383767.png">

通过此界面可以修改本地的SipProfile帐号信息。

接打电话时需要更新对方SipProfile的信息,代码如下:

[java] view plaincopyprint?
  1. /**
  2. * Updates the status box at the top of the UI with a messege of your choice.
  3. * @param status The String to display in the status box.
  4. */
  5. publicvoid updateStatus(final String status) {
  6. // Be a good citizen.  Make sure UI changes fire on the UI thread.
  7. this.runOnUiThread(new Runnable() {
  8. publicvoid run() {
  9. TextView labelView = (TextView) findViewById(R.id.sipLabel);
  10. labelView.setText(status);
  11. }
  12. });
  13. }
  14. /**
  15. * Updates the status box with the SIP address of the current call.
  16. * @param call The current, active call.
  17. */
  18. publicvoid updateStatus(SipAudioCall call) {
  19. String useName = call.getPeerProfile().getDisplayName();
  20. if(useName == null) {
  21. useName = call.getPeerProfile().getUserName();
  22. }
  23. updateStatus(useName + "@" + call.getPeerProfile().getSipDomain());
  24. }
/*** Updates the status box at the top of the UI with a messege of your choice.* @param status The String to display in the status box.*/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.sipLabel);labelView.setText(status);}});}/*** Updates the status box with the SIP address of the current call.* @param call The current, active call.*/public void updateStatus(SipAudioCall call) {String useName = call.getPeerProfile().getDisplayName();if(useName == null) {useName = call.getPeerProfile().getUserName();}updateStatus(useName + "@" + call.getPeerProfile().getSipDomain());}

拨电话代码如下:

[java] view plaincopyprint?
  1. /**
  2. * Make an outgoing call.
  3. */
  4. publicvoid initiateCall() {
  5. updateStatus(sipAddress);
  6. try {
  7. SipAudioCall.Listener listener = new SipAudioCall.Listener() {
  8. // Much of the client's interaction with the SIP Stack will
  9. // happen via listeners.  Even making an outgoing call, don't
  10. // forget to set up a listener to set things up once the call is established.
  11. @Override
  12. publicvoid onCallEstablished(SipAudioCall call) {
  13. call.startAudio();
  14. call.setSpeakerMode(true);
  15. call.toggleMute();
  16. updateStatus(call);
  17. }
  18. @Override
  19. publicvoid onCallEnded(SipAudioCall call) {
  20. updateStatus("Ready.");
  21. }
  22. };
  23. call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 30);
  24. }
  25. catch (Exception e) {
  26. Log.i("WalkieTalkieActivity/InitiateCall", "Error when trying to close manager.", e);
  27. if (me != null) {
  28. try {
  29. manager.close(me.getUriString());
  30. } catch (Exception ee) {
  31. Log.i("WalkieTalkieActivity/InitiateCall",
  32. "Error when trying to close manager.", ee);
  33. ee.printStackTrace();
  34. }
  35. }
  36. if (call != null) {
  37. call.close();
  38. }
  39. }
  40. }
/*** Make an outgoing call.*/public void initiateCall() {updateStatus(sipAddress);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.@Overridepublic void onCallEstablished(SipAudioCall call) {call.startAudio();call.setSpeakerMode(true);call.toggleMute();updateStatus(call);}@Overridepublic void onCallEnded(SipAudioCall call) {updateStatus("Ready.");}};call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 30);}catch (Exception e) {Log.i("WalkieTalkieActivity/InitiateCall", "Error when trying to close manager.", e);if (me != null) {try {manager.close(me.getUriString());} catch (Exception ee) {Log.i("WalkieTalkieActivity/InitiateCall","Error when trying to close manager.", ee);ee.printStackTrace();}}if (call != null) {call.close();}}}

接电话代码如下:

[java] view plaincopyprint?
  1. // Set up the intent filter.  This will be used to fire an
  2. // IncomingCallReceiver when someone calls the SIP address used by this
  3. // application.
  4. IntentFilter filter = new IntentFilter();
  5. filter.addAction("android.SipDemo.INCOMING_CALL");
  6. callReceiver = new IncomingCallReceiver();
  7. this.registerReceiver(callReceiver, filter);
// Set up the intent filter.  This will be used to fire an// IncomingCallReceiver when someone calls the SIP address used by this// application.IntentFilter filter = new IntentFilter();filter.addAction("android.SipDemo.INCOMING_CALL");callReceiver = new IncomingCallReceiver();this.registerReceiver(callReceiver, filter);
[java] view plaincopyprint?
  1. package com.example.android.sip;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.net.sip.*;
  6. /**
  7. * Listens for incoming SIP calls, intercepts and hands them off to WalkieTalkieActivity.
  8. */
  9. publicclass IncomingCallReceiver extends BroadcastReceiver {
  10. /**
  11. * Processes the incoming call, answers it, and hands it over to the
  12. * WalkieTalkieActivity.
  13. * @param context The context under which the receiver is running.
  14. * @param intent The intent being received.
  15. */
  16. @Override
  17. publicvoid onReceive(Context context, Intent intent) {
  18. System.out.println("IncomingCallReceiver::::::");
  19. SipAudioCall incomingCall = null;
  20. try {
  21. SipAudioCall.Listener listener = new SipAudioCall.Listener() {
  22. @Override
  23. publicvoid onRinging(SipAudioCall call, SipProfile caller) {
  24. try {
  25. call.answerCall(30);
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. };
  31. WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
  32. incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
  33. incomingCall.answerCall(30);
  34. incomingCall.startAudio();
  35. incomingCall.setSpeakerMode(true);
  36. if(incomingCall.isMuted()) {
  37. incomingCall.toggleMute();
  38. }
  39. wtActivity.call = incomingCall;
  40. wtActivity.updateStatus(incomingCall);
  41. } catch (Exception e) {
  42. if (incomingCall != null) {
  43. incomingCall.close();
  44. }
  45. }
  46. }
  47. }
package com.example.android.sip;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.sip.*;/*** Listens for incoming SIP calls, intercepts and hands them off to WalkieTalkieActivity.*/
public class IncomingCallReceiver extends BroadcastReceiver {/*** Processes the incoming call, answers it, and hands it over to the* WalkieTalkieActivity.* @param context The context under which the receiver is running.* @param intent The intent being received.*/@Overridepublic void onReceive(Context context, Intent intent) {System.out.println("IncomingCallReceiver::::::");SipAudioCall incomingCall = null;try {SipAudioCall.Listener listener = new SipAudioCall.Listener() {@Overridepublic void onRinging(SipAudioCall call, SipProfile caller) {try {call.answerCall(30);} catch (Exception e) {e.printStackTrace();}}};WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;incomingCall = wtActivity.manager.takeAudioCall(intent, listener);incomingCall.answerCall(30);incomingCall.startAudio();incomingCall.setSpeakerMode(true);if(incomingCall.isMuted()) {incomingCall.toggleMute();}wtActivity.call = incomingCall;wtActivity.updateStatus(incomingCall);} catch (Exception e) {if (incomingCall != null) {incomingCall.close();}}}
}

设置本地sip:

[java] view plaincopyprint?
  1. /**
  2. * Handles SIP authentication settings for the Walkie Talkie app.
  3. */
  4. publicclass SipSettings extends PreferenceActivity {
  5. @Override
  6. publicvoid onCreate(Bundle savedInstanceState) {
  7. // Note that none of the preferences are actually defined here.
  8. // They're all in the XML file res/xml/preferences.xml.
  9. super.onCreate(savedInstanceState);
  10. addPreferencesFromResource(R.xml.preferences);
  11. System.out.println("SipSettings::::::::::");
  12. }
  13. }
/*** Handles SIP authentication settings for the Walkie Talkie app.*/
public class SipSettings extends PreferenceActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {// Note that none of the preferences are actually defined here.// They're all in the XML file res/xml/preferences.xml.super.onCreate(savedInstanceState);addPreferencesFromResource(R.xml.preferences);System.out.println("SipSettings::::::::::");}
}

转载于:https://www.cnblogs.com/sy171822716/archive/2012/08/16/2642187.html

SIP音调通话调研结果相关推荐

  1. android sip服务器,android sip协议通话实现

    android sip协议通话代码实现 简介 android里面的VOIP网络通话基于sip(Session initiation protocol)协议:android已经集成了sip协议栈,并提供 ...

  2. 智能会议系统(35)---深入浅出sip协议

    深入浅出sip协议 传统电话是电磁波的通信,当电话技术发展到IP技术时代,SIP协议成为了电话通信标准协议,不仅可以通电话.还可以收发信息.视频.开会.放PPT.事实上,今天的通信业已全面采用SIP协 ...

  3. 跨平台SIP 客户端-linphone下载、使用

    linphone 官网地址:https://www.linphone.org/ Github:https://github.com/BelledonneCommunications 开发指南:http ...

  4. SIP INVITE流程

    我们知道在SIP协议的流程中,SIP会话过程是非常重要的.那么对于请求和回复的内容,我们来详细了解一下这些方面的内容吧.那么通过SIP INVITE而发出的一些字段含义我们来着重讲解一下吧. SIP ...

  5. FreePBX 12 SIP协议30分钟自动挂断问题处理

    FreePBX 12 SIP协议30分钟自动挂断问题处理 问题: SIP每次通话几乎恰好在 30 分钟左右掉线,而IAX协议并没有这个问题. 解决方案: 登录管理后台找到Settings =>A ...

  6. sip转webrtc的并实现网页拨打电话

    sip转webrtc的一种方法并实现网页拨打电话(非webrtc调用sdk) sip转webrtc的一种方法并实现网页拨打电话(非webrtc调用sdk),之前的项目是asterisk1.8版本,开发 ...

  7. 16个新职业公布,有的出现在疫情服务中,蕴藏了哪些新机会

    近日,人社部.市场监管总局.国家统计局联合发布了人工智能训练师.呼吸治疗师等16个新职业.这是自2015年版<中华人民共和国职业分类大典>颁布以来发布的第二批新职业.随着新兴技术的应用和人 ...

  8. 呼叫中心服务器类型,呼叫中心常见的几种服务器.doc

    <呼叫中心常见的几种服务器.doc>由会员分享,提供在线免费全文阅读可下载,此文档格式为doc,更多相关<呼叫中心常见的几种服务器.doc>文档请在天天文库搜索. 1.呼叫中 ...

  9. 实现语音对讲_什么是五方通话?智慧电梯SIP五方对讲系统详细方案

    什么是五方通话? 电梯机房 + 轿顶 + 轿箱内 + 底坑 + 值班中心 = 五方通话 五方通话的作用 一.紧急求助:当有人被困在电梯时,可以与值班中心通话,迅速处理,安抚被困人员. 二.警告:当有人 ...

最新文章

  1. 清晰易懂的Focal Loss原理解释
  2. 在arm linux mini2440上移植ntp服务,RTEMS 4.9.5 在 QEMU MINI2440 上的移植发布啦……
  3. Struts2漏洞和Struts Scan工具实战
  4. java虚拟_Java虚拟机(JVM)工作原理
  5. Android 系统(70)---Android刘海屏适配方案
  6. IE7下position:relative的问题
  7. java文件格式转换
  8. JDK1.8下载与安装及环境变量配置
  9. linux运行非法指令,illegal instruction非法指令的解决思路
  10. Keil5.15版本号
  11. 团队个人每天详细计划汇总
  12. Runtime中神奇的exec方法
  13. 未能将“C:\Program Files (x86)\DevExpress 2009.2\Components\Sources\DevExpress.DLL\DevExpress.XtraGrid.v
  14. python搭建下载/上传服务器
  15. System V消息队列报Resource temporarily unavailable 错误
  16. 积极主动沟通说话交流的重要性和案例以及技巧
  17. 喷淋系统在安装算量软件中如何计算工程量?
  18. c语言控制51单片机完成交通信号灯(红绿灯)
  19. 重装java后hadoop配置文件的修改
  20. 历史回顾|创建PG全球生态!PostgresConf.CN2019大会召开

热门文章

  1. python 马赛克还原_马赛克消除还原工具Depix测试
  2. Android中播放音乐的几种方式
  3. 绝密计划:我在阿里打黑工
  4. jar -cvfM0 暂使用 jar cvf不好用
  5. 相机光学(一)——成像系统分辨率的理论
  6. ubuntu16.04+gtx1050驱动安装记录
  7. HDFS操作及命令介绍
  8. 浙江大学翁恺C++自学笔记
  9. java criterion_hibernate Criterion和Criteria
  10. 项目中引入阿里巴巴图标——iconfont图标的使用-svg格式