public abstract class ConnectionService
extends Service
java.lang.Object | ||||
↳ | android.content.Context | |||
↳ | android.content.ContextWrapper | |||
↳ | android.app.Service | |||
↳ | android.telecom.ConnectionService |
一种抽象服务,应该由任何可以拨打电话(VoIP或其他)的应用程序实现,并且希望将这些呼叫集成到内置的电话应用程序中。 一旦实施, ConnectionService
需要两个额外的步骤,才能将其集成到手机应用程序中:
1. 在AndroidManifest.xml中注册
<service android:name="com.example.package.MyConnectionService" android:label="@string/some_label_for_my_connection_service" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"> <intent-filter> <action android:name="android.telecom.ConnectionService" /> </intent-filter> </service>
2. 注册PhoneAccount
与TelecomManager
。
有关更多信息,请参阅PhoneAccount
和registerPhoneAccount(PhoneAccount)
。
一旦用户在电话应用程序设置中注册并启用,电信将绑定到ConnectionService
实施,当它要求ConnectionService
拨打电话或该服务已通过addNewIncomingCall(PhoneAccountHandle, Bundle)
表明有来电时。 然后, ConnectionService
可以预期致电onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)
或onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
其中它应该提供Connection
对象的新实例。 正是通过这个Connection
对象,电信接收状态更新并且ConnectionService
接收诸如应答,拒绝,保持和断开的呼叫命令。
当不再有实时通话时,电信将从 ConnectionService
解除绑定。
Constants |
|
---|---|
String |
SERVICE_INTERFACE 必须声明为由服务处理的 |
Inherited constants |
---|
From class android.app.Service
|
From class android.content.Context
|
From interface android.content.ComponentCallbacks2
|
Public constructors |
|
---|---|
ConnectionService() |
Public methods |
|
---|---|
final void |
addConference(Conference conference) 添加新的电话会议。 |
final void |
addExistingConnection(PhoneAccountHandle phoneAccountHandle, Connection connection) 添加由 |
final void |
conferenceRemoteConnections(RemoteConnection remoteConnection1, RemoteConnection remoteConnection2) 指示相关的 |
final RemoteConnection |
createRemoteIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) 请求其他 |
final RemoteConnection |
createRemoteOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) 要求其他 |
final Collection<Conference> |
getAllConferences() 返回此 |
final Collection<Connection> |
getAllConnections() 返回此 |
final IBinder |
onBind(Intent intent) 将通信信道返回给服务。 |
void |
onConference(Connection connection1, Connection connection2) 会议两个指定的连接。 |
Connection |
onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) 给定一个传入请求,创建一个 |
Connection |
onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) 给出一个输出请求,创建一个 |
void |
onRemoteConferenceAdded(RemoteConference conference) 表示已为现有的 |
void |
onRemoteExistingConnectionAdded(RemoteConnection connection) 当远程添加现有连接时调用。 |
boolean |
onUnbind(Intent intent) 当所有客户端与服务发布的特定接口断开连接时调用。 |
Inherited methods |
|
---|---|
From class android.app.Service
|
|
From class android.content.ContextWrapper
|
|
From class android.content.Context
|
|
From class java.lang.Object
|
|
From interface android.content.ComponentCallbacks2
|
|
From interface android.content.ComponentCallbacks
|
String SERVICE_INTERFACE
必须声明为由服务处理的 Intent
。
常量值:“android.telecom.ConnectionService”
void addConference (Conference conference)
添加新的电话会议。 当通过onConference(Connection, Connection)
或其他方式显式请求创建电话会议时,连接服务应通过调用此方法提供Conference
的实例。 此方法提供的电话会议将一直持续到会议实例调用destroy()
。
Parameters | |
---|---|
conference |
Conference : The new conference object. |
void addExistingConnection (PhoneAccountHandle phoneAccountHandle, Connection connection)
添加由 ConnectionService
创建的连接,并通知电信新连接。
Parameters | |
---|---|
phoneAccountHandle |
PhoneAccountHandle : The phone account handle for the connection. |
connection |
Connection : The connection to add. |
void conferenceRemoteConnections (RemoteConnection remoteConnection1, RemoteConnection remoteConnection2)
向相关的 RemoteConnectionService
表明应将指定的 RemoteConnection
合并成电话会议。
如果会议请求成功,将调用方法 onRemoteConferenceAdded(RemoteConference)
。
Parameters | |
---|---|
remoteConnection1 |
RemoteConnection : The first of the remote connections to conference. |
remoteConnection2 |
RemoteConnection : The second of the remote connections to conference. |
RemoteConnection createRemoteIncomingConnection (PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)
请求其他ConnectionService
根据给定的传入请求创建RemoteConnection
。 这由ConnectionService
s使用,它们在CAPABILITY_CONNECTION_MANAGER
中注册,并希望能够管理基于SIM卡的来电。
Parameters | |
---|---|
connectionManagerPhoneAccount |
PhoneAccountHandle : See description at onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest) . |
request |
ConnectionRequest : Details about the incoming call. |
Returns | |
---|---|
RemoteConnection |
The Connection object to satisfy this call, or null to not handle the call. |
RemoteConnection createRemoteOutgoingConnection (PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)
请求一些其他ConnectionService
在给定传出请求的情况下创建RemoteConnection
。 这被ConnectionService
所使用,它们在CAPABILITY_CONNECTION_MANAGER
中注册并且希望能够使用基于SIM的ConnectionService
来发出其呼出。
Parameters | |
---|---|
connectionManagerPhoneAccount |
PhoneAccountHandle : See description at onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest) . |
request |
ConnectionRequest : Details about the incoming call. |
Returns | |
---|---|
RemoteConnection |
The Connection object to satisfy this call, or null to not handle the call. |
Collection<Conference> getAllConferences ()
返回此 ConnectionService
已承担责任的所有活动 Conference
。
Returns | |
---|---|
Collection<Conference> |
A collection of Conference s created by this ConnectionService . |
Collection<Connection> getAllConnections ()
返回此 ConnectionService
已承担责任的所有活动 Connection
。
Returns | |
---|---|
Collection<Connection> |
A collection of Connection s created by this ConnectionService . |
IBinder onBind (Intent intent)
将通信信道返回给服务。 如果客户端无法绑定到服务,可能会返回null。 返回IBinder
通常是一个复杂的界面已经described using aidl 。
请注意,与其他应用程序组件不同,此处返回的IBinder接口调用可能不会发生在进程的主线程上 。 有关主线程的更多信息可以在Processes and Threads中找到。
Parameters | |
---|---|
intent |
Intent : The Intent that was used to bind to this service, as given to Context.bindService . Note that any extras that were included with the Intent at that point will not be seen here. |
Returns | |
---|---|
IBinder |
Return an IBinder through which clients can call on to the service. |
void onConference (Connection connection1, Connection connection2)
会议两个指定的连接。 当用户请求合并指定的连接到电话会议中时调用。 作为响应,连接服务应该创建一个Conference
的实例并将其传递到addConference(Conference)
。
Parameters | |
---|---|
connection1 |
Connection : A connection to merge into a conference call. |
connection2 |
Connection : A connection to merge into a conference call. |
Connection onCreateIncomingConnection (PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)
给定一个传入请求,创建一个Connection
。 这用于附加到现有的来电。
Parameters | |
---|---|
connectionManagerPhoneAccount |
PhoneAccountHandle : See description at onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest) . |
request |
ConnectionRequest : Details about the incoming call. |
Returns | |
---|---|
Connection |
The Connection object to satisfy this call, or null to not handle the call. |
Connection onCreateOutgoingConnection (PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)
给出一个传出请求创建一个Connection
。 这用于发起新的传出呼叫。
Parameters | |
---|---|
connectionManagerPhoneAccount |
PhoneAccountHandle : The connection manager account to use for managing this call. 如果此参数不是 如果这个参数是 |
request |
ConnectionRequest : Details about the outgoing call. |
Returns | |
---|---|
Connection |
The Connection object to satisfy this call, or the result of an invocation of createFailedConnection(DisconnectCause) to not handle the call. |
void onRemoteConferenceAdded (RemoteConference conference)
表示已为现有的RemoteConnection
创建远程会议。 当这个方法被调用时,这个ConnectionService
应该创建它自己的电话会议表示并使用addConference(Conference)
发送给电信。
这只与在 ConnectionService
注册的 CAPABILITY_CONNECTION_MANAGER
。
Parameters | |
---|---|
conference |
RemoteConference : The remote conference call. |
void onRemoteExistingConnectionAdded (RemoteConnection connection)
当远程添加现有连接时调用。
Parameters | |
---|---|
connection |
RemoteConnection : The existing connection which was added. |
boolean onUnbind (Intent intent)
当所有客户端与服务发布的特定接口断开连接时调用。 默认实现什么也不做,并返回false。
Parameters | |
---|---|
intent |
Intent : The Intent that was used to bind to this service, as given to Context.bindService . Note that any extras that were included with the Intent at that point will not be seen here. |
Returns | |
---|---|
boolean |
Return true if you would like to have the service's onRebind(Intent) method later called when new clients bind to it. |