public class SipManager
extends Object
| java.lang.Object | |
| android.net.sip.SipManager | |
为SIP任务提供API,例如发起SIP连接,并提供对相关SIP服务的访问。 此课程是任何SIP操作的起点。 您可以通过newInstance()获取它的一个实例。
这个类中的API允许你:
SipSession to get ready for making calls or listen for incoming calls. See createSipSession() and getSessionFor().open(). Audio-only SIP calls should be handled with a SipAudioCall, which you can acquire with makeAudioCall() and takeAudioCall().register() and unregister().isOpened() and isRegistered().注意:并非所有基于Android的设备都支持使用SIP的VOIP呼叫。 你应该总是调用isVoipSupported() ,以验证该设备支持VOIP通话和isApiSupported() ,以验证该设备支持SIP的API。 您的应用程序还必须请求INTERNET和USE_SIP权限。
有关使用SIP的更多信息,请阅读 Session Initiation Protocol开发人员指南。
常量(Constants) |
|
|---|---|
String |
EXTRA_CALL_ID 从来电呼叫意图中检索呼叫ID的键。 |
String |
EXTRA_OFFER_SD 从呼入意图中检索提供的会话描述的键。 |
int |
INCOMING_CALL_RESULT_CODE 结果代码将与传入呼叫 |
公共方法(Public methods) |
|
|---|---|
void |
close(String localProfileUri) 关闭指定的配置文件以不拨打/接听电话。 |
SipSession |
createSipSession(SipProfile localProfile, SipSession.Listener listener) 用指定的配置文件创建一个 |
static String |
getCallId(Intent incomingCallIntent) 从指定的来电广播意图获取电话ID。 |
static String |
getOfferSessionDescription(Intent incomingCallIntent) 从指定的来电广播意图获取优惠会话描述。 |
SipSession |
getSessionFor(Intent incomingCallIntent) 获取处理传入呼叫的 |
static boolean |
isApiSupported(Context context) 如果系统支持SIP API,则返回true。 |
static boolean |
isIncomingCallIntent(Intent intent) 检查意图是否是来电广播意图。 |
boolean |
isOpened(String localProfileUri) 检查是否在SIP服务中打开了指定的配置文件以拨打和/或接听电话。 |
boolean |
isRegistered(String localProfileUri) 检查SIP服务是否成功将配置文件注册到SIP提供商(在配置文件中指定)以接收呼叫。 |
static boolean |
isSipWifiOnly(Context context) 如果SIP仅在WIFI上可用,则返回true。 |
static boolean |
isVoipSupported(Context context) 如果系统支持基于SIP的VOIP API,则返回true。 |
SipAudioCall |
makeAudioCall(String localProfileUri, String peerProfileUri, SipAudioCall.Listener listener, int timeout) 创建 |
SipAudioCall |
makeAudioCall(SipProfile localProfile, SipProfile peerProfile, SipAudioCall.Listener listener, int timeout) 创建一个 |
static SipManager |
newInstance(Context context) 创建一个管理器实例。 |
void |
open(SipProfile localProfile, PendingIntent incomingCallPendingIntent, SipRegistrationListener listener) 打开用于拨打电话和/或接收通用SIP呼叫的配置文件。 |
void |
open(SipProfile localProfile) 打开用于进行通用SIP呼叫的配置文件。 |
void |
register(SipProfile localProfile, int expiryTime, SipRegistrationListener listener) 手动将配置文件注册到相应的SIP提供商以接收呼叫。 |
void |
setRegistrationListener(String localProfileUri, SipRegistrationListener listener) 将侦听器设置为侦听注册事件。 |
SipAudioCall |
takeAudioCall(Intent incomingCallIntent, SipAudioCall.Listener listener) 创建 |
void |
unregister(SipProfile localProfile, SipRegistrationListener listener) 手动取消注册相应SIP提供商的配置文件以停止接收其他呼叫。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
String EXTRA_OFFER_SD
从呼入意图中检索提供的会话描述的键。
常量值:“android:sipOfferSD”
int INCOMING_CALL_RESULT_CODE
结果代码将与传入呼叫 PendingIntent一起发回。
常量值:101(0x00000065)
void close (String localProfileUri)
关闭指定的配置文件以不拨打/接听电话。 分配给该配置文件的所有资源也将被释放。
| 参数(Parameters) | |
|---|---|
localProfileUri |
String: the URI of the profile to close |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
SipSession createSipSession (SipProfile localProfile, SipSession.Listener listener)
用指定的配置文件创建一个SipSession 。 使用其他方法(如果适用),而不是直接与SipSession交互。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile the session is associated with |
listener |
SipSession.Listener: to listen to SIP session events |
| 返回(Returns) | |
|---|---|
SipSession |
|
| 抛出异常(Throws) | |
|---|---|
SipException |
|
String getCallId (Intent incomingCallIntent)
从指定的来电广播意图获取电话ID。
| 参数(Parameters) | |
|---|---|
incomingCallIntent |
Intent: the incoming call broadcast intent |
| 返回(Returns) | |
|---|---|
String |
the call ID or null if the intent does not contain it |
String getOfferSessionDescription (Intent incomingCallIntent)
从指定的来电广播意图获取优惠会话描述。
| 参数(Parameters) | |
|---|---|
incomingCallIntent |
Intent: the incoming call broadcast intent |
| 返回(Returns) | |
|---|---|
String |
the offer session description or null if the intent does not have it |
SipSession getSessionFor (Intent incomingCallIntent)
获取处理传入呼叫的SipSession 。 对于音频呼叫,请考虑使用SipAudioCall来处理来电。 见takeAudioCall(Intent, SipAudioCall.Listener) 。 请注意,对于相同的意图,该方法只能被调用一次。 对于相同意图的后续调用,该方法返回null。
| 参数(Parameters) | |
|---|---|
incomingCallIntent |
Intent: the incoming call broadcast intent |
| 返回(Returns) | |
|---|---|
SipSession |
the session object that handles the incoming call |
| 抛出异常(Throws) | |
|---|---|
SipException |
|
boolean isApiSupported (Context context)
如果系统支持SIP API,则返回true。
| 参数(Parameters) | |
|---|---|
context |
Context
|
| 返回(Returns) | |
|---|---|
boolean |
|
boolean isIncomingCallIntent (Intent intent)
检查意图是否是来电广播意图。
| 参数(Parameters) | |
|---|---|
intent |
Intent: the intent in question |
| 返回(Returns) | |
|---|---|
boolean |
true if the intent is an incoming call broadcast intent |
boolean isOpened (String localProfileUri)
检查是否在SIP服务中打开了指定的配置文件以拨打和/或接听电话。
| 参数(Parameters) | |
|---|---|
localProfileUri |
String: the URI of the profile in question |
| 返回(Returns) | |
|---|---|
boolean |
true if the profile is enabled to receive calls |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
boolean isRegistered (String localProfileUri)
检查SIP服务是否成功将配置文件注册到SIP提供商(在配置文件中指定)以接收呼叫。 从此方法返回true也意味着打开配置文件( isOpened(String) )。
| 参数(Parameters) | |
|---|---|
localProfileUri |
String: the URI of the profile in question |
| 返回(Returns) | |
|---|---|
boolean |
true if the profile is registered to the SIP provider; false if the profile has not been opened in the SIP service or the SIP service has not yet successfully registered the profile to the SIP provider |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
boolean isSipWifiOnly (Context context)
如果SIP仅在WIFI上可用,则返回true。
| 参数(Parameters) | |
|---|---|
context |
Context
|
| 返回(Returns) | |
|---|---|
boolean |
|
boolean isVoipSupported (Context context)
如果系统支持基于SIP的VOIP API,则返回true。
| 参数(Parameters) | |
|---|---|
context |
Context
|
| 返回(Returns) | |
|---|---|
boolean |
|
SipAudioCall makeAudioCall (String localProfileUri, String peerProfileUri, SipAudioCall.Listener listener, int timeout)
创建SipAudioCall以进行音频呼叫。 尝试将超时如果呼叫没有内建立timeout秒onError(SipAudioCall, SipErrorCode.TIME_OUT, String)将被调用。
| 参数(Parameters) | |
|---|---|
localProfileUri |
String: URI of the SIP profile to make the call from |
peerProfileUri |
String: URI of the SIP profile to make the call to |
listener |
SipAudioCall.Listener: to listen to the call events from SipAudioCall; can be null |
timeout |
int: the timeout value in seconds. Default value (defined by SIP protocol) is used if timeout is zero or negative. |
| 返回(Returns) | |
|---|---|
SipAudioCall |
a SipAudioCall object |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error or VOIP API is not supported by the device |
SipAudioCall makeAudioCall (SipProfile localProfile, SipProfile peerProfile, SipAudioCall.Listener listener, int timeout)
创建一个SipAudioCall来拨打电话。 尝试将超时如果呼叫没有内建立timeout秒onError(SipAudioCall, SipErrorCode.TIME_OUT, String)将被调用。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile to make the call from |
peerProfile |
SipProfile: the SIP profile to make the call to |
listener |
SipAudioCall.Listener: to listen to the call events from SipAudioCall; can be null |
timeout |
int: the timeout value in seconds. Default value (defined by SIP protocol) is used if timeout is zero or negative. |
| 返回(Returns) | |
|---|---|
SipAudioCall |
a SipAudioCall object |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error or VOIP API is not supported by the device |
SipManager newInstance (Context context)
创建一个管理器实例。 如果SIP API不受支持,则返回null。
| 参数(Parameters) | |
|---|---|
context |
Context: application context for creating the manager object |
| 返回(Returns) | |
|---|---|
SipManager |
the manager instance or null if SIP API is not supported |
void open (SipProfile localProfile, PendingIntent incomingCallPendingIntent, SipRegistrationListener listener)
打开用于拨打电话和/或接收通用SIP呼叫的配置文件。 来电者可以通过makeAudioCall(SipProfile, SipProfile, SipAudioCall.Listener, int)进行后续通话。 如果配置文件中启用了自动注册选项,SIP服务将定期注册配置文件到相应的SIP提供商,以接收来自提供商的呼叫。 当SIP服务收到一个新的呼叫时,它将发送一个带有所提供的操作字符串的意图。 该意图包含额外的呼叫ID和额外的商品会话描述字符串。 使用getCallId(Intent)和getOfferSessionDescription(Intent)来检索这些额外信息。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile to receive incoming calls for |
incomingCallPendingIntent |
PendingIntent: When an incoming call is received, the SIP service will call send(Context, int, Intent) to send back the intent to the caller with INCOMING_CALL_RESULT_CODE as the result code and the intent to fill in the call ID and session description information. It cannot be null. |
listener |
SipRegistrationListener: to listen to registration events; can be null |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if incomingCallPendingIntent is null |
SipException |
if the profile contains incorrect settings or calling the SIP service results in an error |
void open (SipProfile localProfile)
打开用于进行通用SIP呼叫的配置文件。 呼叫者可以通过makeAudioCall(SipProfile, SipProfile, SipAudioCall.Listener, int)进行后续呼叫。 如果有人也希望在配置文件上接收呼叫, open(SipProfile, PendingIntent, SipRegistrationListener)改为使用open(SipProfile, PendingIntent, SipRegistrationListener) 。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile to make calls from |
| 抛出异常(Throws) | |
|---|---|
SipException |
if the profile contains incorrect settings or calling the SIP service results in an error |
void register (SipProfile localProfile, int expiryTime, SipRegistrationListener listener)
手动将配置文件注册到相应的SIP提供商以接收呼叫。 open(SipProfile, PendingIntent, SipRegistrationListener)仍然需要至少调用一次,以便SIP服务在收到来电时通过PendingIntent通知主叫方。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile to register with |
expiryTime |
int: registration expiration time (in seconds) |
listener |
SipRegistrationListener: to listen to the registration events |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
void setRegistrationListener (String localProfileUri, SipRegistrationListener listener)
将侦听器设置为侦听注册事件。 如果配置文件尚未打开以接收呼叫,则open(SipProfile, PendingIntent, SipRegistrationListener) (请参阅open(SipProfile, PendingIntent, SipRegistrationListener) )。
| 参数(Parameters) | |
|---|---|
localProfileUri |
String: the URI of the profile |
listener |
SipRegistrationListener: to listen to registration events; can be null |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
SipAudioCall takeAudioCall (Intent incomingCallIntent, SipAudioCall.Listener listener)
创建一个SipAudioCall来接听来电。 在通话返回之前,听众将收到一个onRinging(SipAudioCall, SipProfile)回onRinging(SipAudioCall, SipProfile) 。
| 参数(Parameters) | |
|---|---|
incomingCallIntent |
Intent: the incoming call broadcast intent |
listener |
SipAudioCall.Listener: to listen to the call events from SipAudioCall; can be null |
| 返回(Returns) | |
|---|---|
SipAudioCall |
a SipAudioCall object |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |
void unregister (SipProfile localProfile, SipRegistrationListener listener)
手动取消注册相应SIP提供商的配置文件以停止接收其他呼叫。 如果启用配置文件中的自动注册选项,这可能会干扰SIP服务中的自动注册过程。
| 参数(Parameters) | |
|---|---|
localProfile |
SipProfile: the SIP profile to register with |
listener |
SipRegistrationListener: to listen to the registration events |
| 抛出异常(Throws) | |
|---|---|
SipException |
if calling the SIP service results in an error |