Android-Session Initiation Protocol(SIP)
来源:互联网 发布:php程序员自我评价 编辑:程序博客网 时间:2024/05/17 06:23
Android includes a full SIP protocol stack and integrated call management services that let applications easily set up outgoing and incoming voice calls, without having to manage sessions, transport-level communication, or audio record or playback directly.
Here are examples of the types of applications that might use the SIP API:
- Video conferencing.
- Instant messaging.
Here are the requirements for developing a SIP application:
- You must have a mobile device that is running Android 2.3 or higher.
- SIP runs over a wireless data connection, so your device must have a data connection (with a mobile data service or Wi-Fi). This means that you can't test on AVD—you can only test on a physical device. For details, see Testing SIP Applications.
- Each participant in the application's communication session must have a SIP account. There are many different SIP providers that offer SIP accounts.
To use SIP, add the following permissions to your application's manifest:
android.permission.USE_SIP
<uses-feature android:name="android.hardware.sip.voip" />
Here are excerpts from the SipDemo manifest:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.sip"> ... <receiver android:name=".IncomingCallReceiver" android:label="Call Receiver"/> ... <uses-sdk android:minSdkVersion="9" /> <uses-permission android:name="android.permission.USE_SIP" /> <uses-permission android:name="android.permission.INTERNET" /> ... <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" /></manifest>》To use the SIP API, your application must create a
SipManager
object. The SipManager
takes care of the following in your application:- Initiating SIP sessions.
- Initiating and receiving calls.
- Registering and unregistering with a SIP provider.
- Verifying session connectivity.
》 You create a SipProfile
object as follows:
public SipProfile mSipProfile = null;...SipProfile.Builder builder = new SipProfile.Builder(username, domain);builder.setPassword(password);mSipProfile = builder.build();
Intent intent = new Intent();intent.setAction("android.SipDemo.INCOMING_CALL");PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);mSipManager.open(mSipProfile, pendingIntent, null);
Finally, this code sets a SipRegistrationListener
on the SipManager
. This tracks whether the SipProfile
was successfully registered with your SIP service provider:
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {public void onRegistering(String localProfileUri) { updateStatus("Registering with SIP Server...");}public void onRegistrationDone(String localProfileUri, long expiryTime) { updateStatus("Ready");} public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) { updateStatus("Registration failed. Please check settings.");}
. For information on downloading and installing the SDK samples, see Getting the Samples.
/*** 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. */ @Override public void onReceive(Context context, Intent intent) { SipAudioCall incomingCall = null; try { SipAudioCall.Listener listener = new SipAudioCall.Listener() { @Override public void onRinging(SipAudioCall call, SipProfile caller) { try { call.answerCall(30); } catch (Exception e) { e.printStackTrace(); } } }; WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context; incomingCall = wtActivity.mSipManager.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(); } } }}>Testing SIP Applications
To test SIP applications, you need the following:
- A mobile device that is running Android 2.3 or higher. SIP runs over wireless, so you must test on an actual device. Testing on AVD won't work.
- A SIP account. There are many different SIP providers that offer SIP accounts.
- If you are placing a call, it must also be to a valid SIP account.
To test a SIP application:
- On your device, connect to wireless (Settings > Wireless & networks > Wi-Fi > Wi-Fi settings).
- Set up your mobile device for testing, as described in Developing on a Device.
- Run your application on your mobile device, as described in Developing on a Device.
- If you are using Android Studio, you can view the application log output by opening the Event Log console (View > Tool Windows > Event Log).
- Ensure your application is configured to launch Logcat automatically when it runs:
- Select Run > Edit Configurations.
- Select the Miscellaneous tab in the Run/Debug Configurations window.
- Under Logcat, select Show logcat automatically then select OK.
- Android-Session Initiation Protocol(SIP)
- Android SIP(Session Initiation Protocol)
- SIP(Session Initiation Protocol)
- RFC3261 SIP: Session Initiation Protocol
- SIP-Session Initiation Protocol(Abstract)
- SIP(Session Initiation Protocol)会话启动协议
- SIP:会话初始化协议(Session Initiation Protocol)
- 会话发起协议(Session Initiation Protocol,缩写SIP)
- SIP(Session Initiation Protocol,会话初始协议)
- The Session Initiation Protocol (SIP) "Join" Header
- Session Initiation Protocol (SIP): Controlling Convergent Networks
- SIP(Session Initiation Protocol,会话初始协议)呼叫过程介绍
- RFC3261 SIP: Session Initiation Protocol 会话发起协议
- SIP: Understanding the Session Initiation Protocol, Second Edition
- Android API Guides---Session Initiation Protocol
- RFC3265 翻译 Session Initiation Protocol (SIP)-Specific Event Notification SIP-特定事件通
- SIP Call Flow - Initiation of IMS Session
- SIP(Session Initial Protocol) Overview
- 保存输入和读取文件【python】
- android EditText 设置密码明文 密文 显示方法
- Java API实现WebSocket客户端
- 如何查找安装的 Java 版本(而不在 Windows 或 Mac 中运行小应用程序)?
- ubuntu更新时"Not enough free disk space"
- Android-Session Initiation Protocol(SIP)
- Linux Socket绑定的端口号和实际端口号不一致
- 黑马程序员——Eclipse快捷键
- 组合与继承
- msf笔记
- SQLLDR
- linux性能监控工具
- uva10603
- mac上一键配置和安装adb驱动或者环境