SIP音调通话调研结果
android中Sip音频通话调研结果
- <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配置文件如下所示:
- <PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android">
- <EditTextPreference
- android:name="SIP Username"
- android:summary="Username for your SIP Account"
- android:defaultValue=""
- android:title="Enter Username"
- android:key="namePref"/>
- <EditTextPreference
- android:name="SIP Domain"
- android:summary="Domain for your SIP Account"
- android:defaultValue=""
- android:title="Enter Domain"
- android:key="domainPref"/>
- <EditTextPreference
- android:name="SIP Password"
- android:summary="Password for your SIP Account"
- android:defaultValue=""
- android:title="Enter Password"
- android:key="passPref"
- android:password="true"
- />
- </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的代码如下:
- publicvoid updatePreferences() {
- Intent settingsActivity = new Intent(getBaseContext(),
- SipSettings.class);
- startActivity(settingsActivity);
- }
public void updatePreferences() {Intent settingsActivity = new Intent(getBaseContext(),SipSettings.class);startActivity(settingsActivity);}
调用updatePreferences()方法会有如下的效果图显示:
- <img alt="" src="https://img-blog.csdnimg.cn/2022010703245383767.png">
通过此界面可以修改本地的SipProfile帐号信息。
接打电话时需要更新对方SipProfile的信息,代码如下:
- /**
- * 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.
- */
- publicvoid updateStatus(final String status) {
- // Be a good citizen. Make sure UI changes fire on the UI thread.
- this.runOnUiThread(new Runnable() {
- publicvoid 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.
- */
- publicvoid updateStatus(SipAudioCall call) {
- String useName = call.getPeerProfile().getDisplayName();
- if(useName == null) {
- useName = call.getPeerProfile().getUserName();
- }
- updateStatus(useName + "@" + call.getPeerProfile().getSipDomain());
- }
/*** 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());}
拨电话代码如下:
- /**
- * Make an outgoing call.
- */
- publicvoid 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.
- @Override
- publicvoid onCallEstablished(SipAudioCall call) {
- call.startAudio();
- call.setSpeakerMode(true);
- call.toggleMute();
- updateStatus(call);
- }
- @Override
- publicvoid 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();
- }
- }
- }
/*** 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();}}}
接电话代码如下:
- // 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);
// 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);
- 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.
- */
- publicclass 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.
- */
- @Override
- publicvoid onReceive(Context context, Intent intent) {
- System.out.println("IncomingCallReceiver::::::");
- SipAudioCall incomingCall = null;
- try {
- SipAudioCall.Listener listener = new SipAudioCall.Listener() {
- @Override
- publicvoid 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();
- }
- }
- }
- }
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:
- /**
- * Handles SIP authentication settings for the Walkie Talkie app.
- */
- publicclass SipSettings extends PreferenceActivity {
- @Override
- publicvoid 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::::::::::");
- }
- }
/*** 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音调通话调研结果相关推荐
- android sip服务器,android sip协议通话实现
android sip协议通话代码实现 简介 android里面的VOIP网络通话基于sip(Session initiation protocol)协议:android已经集成了sip协议栈,并提供 ...
- 智能会议系统(35)---深入浅出sip协议
深入浅出sip协议 传统电话是电磁波的通信,当电话技术发展到IP技术时代,SIP协议成为了电话通信标准协议,不仅可以通电话.还可以收发信息.视频.开会.放PPT.事实上,今天的通信业已全面采用SIP协 ...
- 跨平台SIP 客户端-linphone下载、使用
linphone 官网地址:https://www.linphone.org/ Github:https://github.com/BelledonneCommunications 开发指南:http ...
- SIP INVITE流程
我们知道在SIP协议的流程中,SIP会话过程是非常重要的.那么对于请求和回复的内容,我们来详细了解一下这些方面的内容吧.那么通过SIP INVITE而发出的一些字段含义我们来着重讲解一下吧. SIP ...
- FreePBX 12 SIP协议30分钟自动挂断问题处理
FreePBX 12 SIP协议30分钟自动挂断问题处理 问题: SIP每次通话几乎恰好在 30 分钟左右掉线,而IAX协议并没有这个问题. 解决方案: 登录管理后台找到Settings =>A ...
- sip转webrtc的并实现网页拨打电话
sip转webrtc的一种方法并实现网页拨打电话(非webrtc调用sdk) sip转webrtc的一种方法并实现网页拨打电话(非webrtc调用sdk),之前的项目是asterisk1.8版本,开发 ...
- 16个新职业公布,有的出现在疫情服务中,蕴藏了哪些新机会
近日,人社部.市场监管总局.国家统计局联合发布了人工智能训练师.呼吸治疗师等16个新职业.这是自2015年版<中华人民共和国职业分类大典>颁布以来发布的第二批新职业.随着新兴技术的应用和人 ...
- 呼叫中心服务器类型,呼叫中心常见的几种服务器.doc
<呼叫中心常见的几种服务器.doc>由会员分享,提供在线免费全文阅读可下载,此文档格式为doc,更多相关<呼叫中心常见的几种服务器.doc>文档请在天天文库搜索. 1.呼叫中 ...
- 实现语音对讲_什么是五方通话?智慧电梯SIP五方对讲系统详细方案
什么是五方通话? 电梯机房 + 轿顶 + 轿箱内 + 底坑 + 值班中心 = 五方通话 五方通话的作用 一.紧急求助:当有人被困在电梯时,可以与值班中心通话,迅速处理,安抚被困人员. 二.警告:当有人 ...
最新文章
- 清晰易懂的Focal Loss原理解释
- 在arm linux mini2440上移植ntp服务,RTEMS 4.9.5 在 QEMU MINI2440 上的移植发布啦……
- Struts2漏洞和Struts Scan工具实战
- java虚拟_Java虚拟机(JVM)工作原理
- Android 系统(70)---Android刘海屏适配方案
- IE7下position:relative的问题
- java文件格式转换
- JDK1.8下载与安装及环境变量配置
- linux运行非法指令,illegal instruction非法指令的解决思路
- Keil5.15版本号
- 团队个人每天详细计划汇总
- Runtime中神奇的exec方法
- 未能将“C:\Program Files (x86)\DevExpress 2009.2\Components\Sources\DevExpress.DLL\DevExpress.XtraGrid.v
- python搭建下载/上传服务器
- System V消息队列报Resource temporarily unavailable 错误
- 积极主动沟通说话交流的重要性和案例以及技巧
- 喷淋系统在安装算量软件中如何计算工程量?
- c语言控制51单片机完成交通信号灯(红绿灯)
- 重装java后hadoop配置文件的修改
- 历史回顾|创建PG全球生态!PostgresConf.CN2019大会召开