Most visited

Recently visited

Added in API level 23

ConnectionService

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. 注册PhoneAccountTelecomManager
有关更多信息,请参阅PhoneAccountregisterPhoneAccount(PhoneAccount)

一旦用户在电话应用程序设置中注册并启用,电信将绑定到ConnectionService实施,当它要求ConnectionService拨打电话或该服务已通过addNewIncomingCall(PhoneAccountHandle, Bundle)表明有来电时。 然后, ConnectionService可以预期致电onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)其中它应该提供Connection对象的新实例。 正是通过这个Connection对象,电信接收状态更新并且ConnectionService接收诸如应答,拒绝,保持和断开的呼叫命令。

当不再有实时通话时,电信将从 ConnectionService解除绑定。

Summary

Constants

String SERVICE_INTERFACE

必须声明为由服务处理的 Intent

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)

添加由 ConnectionService创建的连接并将新连接通知给电信公司。

final void conferenceRemoteConnections(RemoteConnection remoteConnection1, RemoteConnection remoteConnection2)

指示相关的 RemoteConnectionService指定的 RemoteConnection应合并成电话会议。

final RemoteConnection createRemoteIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)

请求其他 ConnectionService在给定传入请求的情况下创建一个 RemoteConnection

final RemoteConnection createRemoteOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)

要求其他 ConnectionService在给定传出请求的情况下创建 RemoteConnection

final Collection<Conference> getAllConferences()

返回此 ConnectionService已承担责任的所有活动 Conference

final Collection<Connection> getAllConnections()

返回此 ConnectionService已承担责任的所有活动 Connection

final IBinder onBind(Intent intent)

将通信信道返回给服务。

void onConference(Connection connection1, Connection connection2)

会议两个指定的连接。

Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)

给定一个传入请求,创建一个 Connection

Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)

给出一个输出请求,创建一个 Connection

void onRemoteConferenceAdded(RemoteConference conference)

表示已为现有的 RemoteConnection创建远程会议。

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

Constants

SERVICE_INTERFACE

Added in API level 23
String SERVICE_INTERFACE

必须声明为由服务处理的 Intent

常量值:“android.telecom.ConnectionService”

Public constructors

ConnectionService

Added in API level 23
ConnectionService ()

Public methods

addConference

Added in API level 23
void addConference (Conference conference)

添加新的电话会议。 当通过onConference(Connection, Connection)或其他方式显式请求创建电话会议时,连接服务应通过调用此方法提供Conference的实例。 此方法提供的电话会议将一直持续到会议实例调用destroy()

Parameters
conference Conference: The new conference object.

addExistingConnection

Added in API level 23
void addExistingConnection (PhoneAccountHandle phoneAccountHandle, 
                Connection connection)

添加由 ConnectionService创建的连接,并通知电信新连接。

Parameters
phoneAccountHandle PhoneAccountHandle: The phone account handle for the connection.
connection Connection: The connection to add.

conferenceRemoteConnections

Added in API level 23
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.

createRemoteIncomingConnection

Added in API level 23
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.

createRemoteOutgoingConnection

Added in API level 23
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.

getAllConferences

Added in API level 24
Collection<Conference> getAllConferences ()

返回此 ConnectionService已承担责任的所有活动 Conference

Returns
Collection<Conference> A collection of Conferences created by this ConnectionService.

getAllConnections

Added in API level 23
Collection<Connection> getAllConnections ()

返回此 ConnectionService已承担责任的所有活动 Connection

Returns
Collection<Connection> A collection of Connections created by this ConnectionService.

onBind

Added in API level 23
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.

onConference

Added in API level 23
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.

onCreateIncomingConnection

Added in API level 23
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.

onCreateOutgoingConnection

Added in API level 23
Connection onCreateOutgoingConnection (PhoneAccountHandle connectionManagerPhoneAccount, 
                ConnectionRequest request)

给出一个传出请求创建一个Connection 这用于发起新的传出呼叫。

Parameters
connectionManagerPhoneAccount PhoneAccountHandle: The connection manager account to use for managing this call.

如果此参数不是null ,则表示此ConnectionService已注册一个或多个PhoneAccountCAPABILITY_CONNECTION_MANAGER 此参数将包含这些PhoneAccount之一,而request将包含另一个(通常但不总是不同)的PhoneAccount ,用于实际建立连接。

如果这个参数是null ,这意味着这个ConnectionService被要求直接连接。 getAccountHandle()参数request将是一个PhoneAccount这个注册ConnectionService用于建立连接。

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.

onRemoteConferenceAdded

Added in API level 23
void onRemoteConferenceAdded (RemoteConference conference)

表示已为现有的RemoteConnection创建远程会议。 当这个方法被调用时,这个ConnectionService应该创建它自己的电话会议表示并使用addConference(Conference)发送给电信。

这只与在 ConnectionService注册的 CAPABILITY_CONNECTION_MANAGER

Parameters
conference RemoteConference: The remote conference call.

onRemoteExistingConnectionAdded

Added in API level 23
void onRemoteExistingConnectionAdded (RemoteConnection connection)

当远程添加现有连接时调用。

Parameters
connection RemoteConnection: The existing connection which was added.

onUnbind

Added in API level 23
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.

Hooray!