Class SAAgentV2
- java.lang.Object
-
- com.samsung.android.sdk.accessory.SAAgentV2
-
public abstract class SAAgentV2 extends java.lang.Object
SAAgentV2 provides the main interface between Service Provider and Service Consumer applications and Samsung Accessory Service Framework.Developer Guides
Both Service Provider and Service Consumer applications must declare a subclass of this class and implement the actions of an Accessory Peer Agent (Service Provider or Service Consumer). The application has to add a Broadcast Receiver into the Android Manifest file for
ACTION_REGISTRATION_REQUIRED
action to register an application to Samsung Accessory Service Framework and theACTION_SERVICE_CONNECTION_REQUESTED
action to receive a service connection request.When you build your application in release mode, you must add several -keep lines in the ProGuard configuration file of your application to prevent ProGuard from renaming your subclasses of
SAAgentV2
andSASocket
. (ProGuard is a tool integrated into the Android build system that obfuscates the code by renaming its classes and methods.)For more information about How to configure ProGuard, please visit the ProGuard page of Android Development Site.
For more information about using Accessory, please refer to the Accessory Programming Guide.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static interface
SAAgentV2.RequestAgentCallback
Callback interface forrequestAgent(Context, String, RequestAgentCallback)
to receiveSAAgentV2
instance.
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String
ACTION_REGISTRATION_REQUIRED
Broadcast Action: Indicates that an installed peer agent has been required to register.static java.lang.String
ACTION_SERVICE_CONNECTION_REQUESTED
Broadcast Action: Indicates that an incoming service connection request from remote Accessory Peer Agent has been received.static int
AUTHENTICATION_FAILURE_PEER_AGENT_NOT_SUPPORTED
The remote Accessory Peer Agent does not support authentication.static int
AUTHENTICATION_FAILURE_TOKEN_NOT_GENERATED
The remote Accessory Peer Agent's authentication token is not generated.static int
AUTHENTICATION_SUCCESS
Authentication request succeeded.static int
CONNECTION_ALREADY_EXIST
Service Connection establishment failed as another Service Connection request with the same remote Accessory Peer Agent has been already established.static int
CONNECTION_DUPLICATE_REQUEST
Service Connection establishment failed as another attempt with same remote Accessory Peer Agent is still in progress.static int
CONNECTION_FAILURE_DEVICE_UNREACHABLE
Service Connection establishment failed as the remote Accessory Peer Agent is unreachable.static int
CONNECTION_FAILURE_INVALID_PEERAGENT
Service Connection establishment failed as theSAPeerAgent
input argument is null or invalid.static int
CONNECTION_FAILURE_NETWORK
Service Connection establishment failed due to network errors.static int
CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE
Service Connection establishment failed as the remote Accessory Peer Agent does not give any response.static int
CONNECTION_FAILURE_PEERAGENT_REJECTED
Service Connection establishment failed as the remote Accessory Peer Agent rejected the request.static int
CONNECTION_FAILURE_SERVICE_LIMIT_REACHED
Service Connection establishment failed as the service limit set by the Accessory Peer Agent has been reached.static int
CONNECTION_SUCCESS
Service Connection has been established successfully.static int
ERROR_AGENT_REQUEST_IN_PROGRESS
Requested Agent Class is being released.static int
ERROR_CLASS_NOT_FOUND
Requested Agent Class is not found.static int
ERROR_CONNECTION_INVALID_PARAM
Data kept by Samsung Accessory Service Framework was lost and cannot be recovered from this error in runtime.static int
ERROR_CONSTRUCTOR_EXCEPTION
Requested Agent Class constructor threw an exception.static int
ERROR_CONSTRUCTOR_NOT_FOUND
Requested Agent Class Constructor is not found.static int
ERROR_FATAL
Fatal error occurred such as binding failure or if the Samsung Accessory Service Framework has stopped.static int
ERROR_PERMISSION_DENIED
Binding to Samsung Accessory Service failed due to permission issue.static int
ERROR_PERMISSION_FAILED
Binding to Samsung Accessory Service failed due to permission mismatch.static int
ERROR_SDK_NOT_INITIALIZED
Samsung Accessory SDK is not initialized.static int
FINDPEER_DEVICE_NOT_CONNECTED
Accessory Devices are not connected.static int
FINDPEER_DUPLICATE_REQUEST
Another request to find an Accessory Peer Agent callingfindPeerAgents()
is still in progress.static int
FINDPEER_SERVICE_NOT_FOUND
No matching Accessory Peer Agents exist on connected Accessory Devices.static int
PEER_AGENT_AVAILABLE
Accessory Peer Agents have been available on a remote Accessory Device.static int
PEER_AGENT_FOUND
Accessory Peer Agents have been found.static int
PEER_AGENT_UNAVAILABLE
Accessory Peer Agents have been unavailable on a remote Accessory Device.
-
Constructor Summary
Constructors Constructor and Description SAAgentV2(java.lang.String name, android.content.Context context)
Creates anSAAgentV2
instance with the specified name.SAAgentV2(java.lang.String name, android.content.Context context, java.lang.Class<? extends SASocket> socketClass)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description protected void
acceptServiceConnectionRequest(SAPeerAgent peerAgent)
Accepts a Service Connection request from the remote Accessory Peer Agent.protected void
authenticatePeerAgent(SAPeerAgent peerAgent)
Authenticates an Accessory Peer Agent.protected void
findPeerAgents()
Finds matching Accessory Peer Agents.int
getServiceChannelId(int index)
Gets the service channel ID at the specific index of the list that is declared in the Service Profile XML.int
getServiceChannelSize()
Gets the size of the service channel list that is declared in the Service Profile XML.java.lang.String
getServiceProfileId()
Gets the service profile ID that is declared in the Service Profile XML.java.lang.String
getServiceProfileName()
Gets the service profile name that is declared in the Service Profile XML.protected void
onAuthenticationResponse(SAPeerAgent peerAgent, SAAuthenticationToken authToken, int code)
Called when the Accessory Peer Agent authentication is completed.protected void
onError(SAPeerAgent peerAgent, java.lang.String errorMessage, int errorCode)
Called when anSAAgentV2
error occurs in Samsung Accessory Service Framework.protected void
onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result)
Called when the discovery for matching Accessory Peer Agents is completed.protected void
onPeerAgentsUpdated(SAPeerAgent[] peerAgents, int result)
Called when the status of remote Accessory Peer Agent on a connected remote Accessory Devices changes.protected void
onServiceConnectionRequested(SAPeerAgent peerAgent)
Called when a remote Accessory Peer Agent requests a Service Connection.protected void
onServiceConnectionResponse(SAPeerAgent peerAgent, SASocket socket, int result)
Called when a Service Connection to a remote Accessory Peer Agent is established or failed.protected void
rejectServiceConnectionRequest(SAPeerAgent peerAgent)
Rejects a Service Connection request from the remote Accessory Peer Agent.void
releaseAgent()
static void
requestAgent(android.content.Context context, java.lang.String agentImplClass, SAAgentV2.RequestAgentCallback callback)
protected void
requestServiceConnection(SAPeerAgent peerAgent)
Requests a Service Connection with a remote Accessory Peer Agent.
-
-
-
Field Detail
-
PEER_AGENT_FOUND
public static final int PEER_AGENT_FOUND
Accessory Peer Agents have been found.Constant Value: 0 (0x00000000)
- Since:
- 2.6.0
- See Also:
onFindPeerAgentsResponse(SAPeerAgent[], int)
, Constant Field Values
-
PEER_AGENT_AVAILABLE
public static final int PEER_AGENT_AVAILABLE
Accessory Peer Agents have been available on a remote Accessory Device.Constant Value: 1 (0x00000001)
- Since:
- 2.6.0
- See Also:
onPeerAgentsUpdated(SAPeerAgent[], int)
, Constant Field Values
-
PEER_AGENT_UNAVAILABLE
public static final int PEER_AGENT_UNAVAILABLE
Accessory Peer Agents have been unavailable on a remote Accessory Device. For example, the application package containing the Accessory Peer Agent was uninstalled on the remote Accessory Device.Constant Value: 2 (0x00000002)
- Since:
- 2.6.0
- See Also:
onPeerAgentsUpdated(SAPeerAgent[], int)
, Constant Field Values
-
FINDPEER_DEVICE_NOT_CONNECTED
public static final int FINDPEER_DEVICE_NOT_CONNECTED
Accessory Devices are not connected.Constant Value: 1793 (0x00000701)
- Since:
- 2.6.0
- See Also:
onFindPeerAgentsResponse(SAPeerAgent[], int)
, Constant Field Values
-
FINDPEER_SERVICE_NOT_FOUND
public static final int FINDPEER_SERVICE_NOT_FOUND
No matching Accessory Peer Agents exist on connected Accessory Devices.Constant Value: 1794 (0x00000702)
- Since:
- 2.6.0
- See Also:
onFindPeerAgentsResponse(SAPeerAgent[], int)
, Constant Field Values
-
FINDPEER_DUPLICATE_REQUEST
public static final int FINDPEER_DUPLICATE_REQUEST
Another request to find an Accessory Peer Agent callingfindPeerAgents()
is still in progress.Constant Value: 3085 (0x00000C0D)
- Since:
- 2.6.0
- See Also:
onFindPeerAgentsResponse(SAPeerAgent[], int)
, Constant Field Values
-
CONNECTION_SUCCESS
public static final int CONNECTION_SUCCESS
Service Connection has been established successfully.Constant Value: 0 (0x00000000)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
ERROR_CONNECTION_INVALID_PARAM
public static final int ERROR_CONNECTION_INVALID_PARAM
Data kept by Samsung Accessory Service Framework was lost and cannot be recovered from this error in runtime. User may need to reboot the device.Constant Value: 1025 (0x00000401)
- Since:
- 2.6.0
- See Also:
onError(SAPeerAgent, String, int)
, Constant Field Values
-
CONNECTION_FAILURE_DEVICE_UNREACHABLE
public static final int CONNECTION_FAILURE_DEVICE_UNREACHABLE
Service Connection establishment failed as the remote Accessory Peer Agent is unreachable.Constant Value: 1028 (0x00000404)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_ALREADY_EXIST
public static final int CONNECTION_ALREADY_EXIST
Service Connection establishment failed as another Service Connection request with the same remote Accessory Peer Agent has been already established.Constant Value: 1029 (0x00000405)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE
public static final int CONNECTION_FAILURE_PEERAGENT_NO_RESPONSE
Service Connection establishment failed as the remote Accessory Peer Agent does not give any response.Constant Value: 1030 (0x00000406)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_FAILURE_PEERAGENT_REJECTED
public static final int CONNECTION_FAILURE_PEERAGENT_REJECTED
Service Connection establishment failed as the remote Accessory Peer Agent rejected the request.Constant Value: 1031 (0x00000407)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_FAILURE_INVALID_PEERAGENT
public static final int CONNECTION_FAILURE_INVALID_PEERAGENT
Service Connection establishment failed as theSAPeerAgent
input argument is null or invalid.Constant Value: 1033 (0x00000409)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_DUPLICATE_REQUEST
public static final int CONNECTION_DUPLICATE_REQUEST
Service Connection establishment failed as another attempt with same remote Accessory Peer Agent is still in progress.Constant Value: 1040 (0x00000410)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_FAILURE_SERVICE_LIMIT_REACHED
public static final int CONNECTION_FAILURE_SERVICE_LIMIT_REACHED
Service Connection establishment failed as the service limit set by the Accessory Peer Agent has been reached.Constant Value: 1037 (0x0000040D)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
CONNECTION_FAILURE_NETWORK
public static final int CONNECTION_FAILURE_NETWORK
Service Connection establishment failed due to network errors.Constant Value: 1280 (0x00000500)
- Since:
- 2.6.0
- See Also:
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
, Constant Field Values
-
AUTHENTICATION_SUCCESS
public static final int AUTHENTICATION_SUCCESS
Authentication request succeeded.Constant Value: 0 (0x00000000)
- Since:
- 2.6.0
- See Also:
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
, Constant Field Values
-
AUTHENTICATION_FAILURE_TOKEN_NOT_GENERATED
public static final int AUTHENTICATION_FAILURE_TOKEN_NOT_GENERATED
The remote Accessory Peer Agent's authentication token is not generated.Constant Value: 1545 (0x00000609)
- Since:
- 2.6.0
- See Also:
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
, Constant Field Values
-
AUTHENTICATION_FAILURE_PEER_AGENT_NOT_SUPPORTED
public static final int AUTHENTICATION_FAILURE_PEER_AGENT_NOT_SUPPORTED
The remote Accessory Peer Agent does not support authentication.Constant Value: 1546 (0x00000610)
- Since:
- 2.6.0
- See Also:
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
, Constant Field Values
-
ERROR_FATAL
public static final int ERROR_FATAL
Fatal error occurred such as binding failure or if the Samsung Accessory Service Framework has stopped.Constant Value: 2048 (0x00000800)
- Since:
- 2.6.0
- See Also:
onError(SAPeerAgent, String, int)
, Constant Field Values
-
ERROR_SDK_NOT_INITIALIZED
public static final int ERROR_SDK_NOT_INITIALIZED
Samsung Accessory SDK is not initialized. All Service Provider and Service Consumer applications are expected to callSA.initialize(android.content.Context)
to initialize the Samsung Accessory SDK before using it.Constant Value: 2049 (0x00000801)
- Since:
- 2.6.0
- See Also:
onError(SAPeerAgent, String, int)
, Constant Field Values
-
ERROR_PERMISSION_DENIED
public static final int ERROR_PERMISSION_DENIED
Binding to Samsung Accessory Service failed due to permission issue. It's advised to check the required permission in the application manifest file.Constant Value: 2304 (0x00000900)
- Since:
- 2.6.0
- See Also:
onError(SAPeerAgent, String, int)
, Constant Field Values
-
ERROR_PERMISSION_FAILED
public static final int ERROR_PERMISSION_FAILED
Binding to Samsung Accessory Service failed due to permission mismatch. It's advised to reinstall the application as the Samsung Accessory Service Framework is installed after the application installation.Constant Value: 2305 (0x00000901)
- Since:
- 2.6.0
- See Also:
onError(SAPeerAgent, String, int)
, Constant Field Values
-
ERROR_CLASS_NOT_FOUND
public static final int ERROR_CLASS_NOT_FOUND
Requested Agent Class is not found. Verify the class name passed inrequestAgent(Context, String, RequestAgentCallback)
Constant Value: 2561 (0x0A01)
- Since:
- 2.6.0
- See Also:
SAAgentV2.RequestAgentCallback.onError(int, String)
, Constant Field Values
-
ERROR_CONSTRUCTOR_NOT_FOUND
public static final int ERROR_CONSTRUCTOR_NOT_FOUND
Requested Agent Class Constructor is not found. Verify the agent class which name is passed inrequestAgent(Context, String, RequestAgentCallback)
has a constructor with Context argument.Constant Value: 2562 (0x0A02)
- Since:
- 2.6.0
- See Also:
SAAgentV2.RequestAgentCallback.onError(int, String)
, Constant Field Values
-
ERROR_CONSTRUCTOR_EXCEPTION
public static final int ERROR_CONSTRUCTOR_EXCEPTION
Requested Agent Class constructor threw an exception. Check the constructor code of the class which name is passed inrequestAgent(Context, String, RequestAgentCallback)
.Constant Value: 2563 (0x0A03)
- Since:
- 2.6.0
- See Also:
SAAgentV2.RequestAgentCallback.onError(int, String)
, Constant Field Values
-
ERROR_AGENT_REQUEST_IN_PROGRESS
public static final int ERROR_AGENT_REQUEST_IN_PROGRESS
Requested Agent Class is being released. Release AgentreleaseAgent()
is still in progress. CallrequestAgent(Context, String, RequestAgentCallback)
after sometime.Constant Value: 2564 (0x0A04)
- Since:
- 2.6.0
- See Also:
SAAgentV2.RequestAgentCallback.onError(int, String)
, Constant Field Values
-
ACTION_SERVICE_CONNECTION_REQUESTED
public static final java.lang.String ACTION_SERVICE_CONNECTION_REQUESTED
Broadcast Action: Indicates that an incoming service connection request from remote Accessory Peer Agent has been received.Note:The designated broadcast receiver, "com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" must be registered in the receiving application's manifest file.
<application ... <receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" > <intent-filter> <action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" /> </intent-filter> </receiver> ... </application>
Constant Value: "com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED"
- Since:
- 2.6.0
- See Also:
- Constant Field Values
-
ACTION_REGISTRATION_REQUIRED
public static final java.lang.String ACTION_REGISTRATION_REQUIRED
Broadcast Action: Indicates that an installed peer agent has been required to register.Note:The designated broadcast receiver, "com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" must be registered in the receiving application's manifest file.
<application ... <receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver"> <intent-filter> <action android:name="com.samsung.accessory.action.REGISTER_AGENT"/> </intent-filter> </receiver> ... </application>
Constant Value: "com.samsung.accessory.action.REGISTER_AGENT"
- Since:
- 2.6.0
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SAAgentV2
public SAAgentV2(java.lang.String name, android.content.Context context)
Creates anSAAgentV2
instance with the specified name.Note: All Service Provider and Service Consumer applications must implement the public default constructor and never call it. The constructor is dynamically referenced by Samsung Accessory SDK. Your application must use this constructor if it makes use of only Message Service feature. Use
SAAgentV2(String, Context, Class)
if it makes use of both Service Connection and Message Service feature.- Parameters:
name
- The name for the derived subclass that extendsSAAgentV2
base class.context
- App context- Since:
- 2.6.0
-
SAAgentV2
public SAAgentV2(java.lang.String name, android.content.Context context, java.lang.Class<? extends SASocket> socketClass)
-
-
Method Detail
-
requestAgent
public static void requestAgent(android.content.Context context, java.lang.String agentImplClass, SAAgentV2.RequestAgentCallback callback)
Request an instance ofSAAgentV2
from the static HashMap saved inSAAgentV2
.Note: All Service Provider and Service Consumer applications should call this method to create or get
SAAgentV2
instance.- Parameters:
context
- App contextagentImplClass
- The name of the application that implementation ClassSAAgentV2
.callback
- The instance ofSAAgentV2.RequestAgentCallback
.- Since:
- 2.6.0
-
releaseAgent
public void releaseAgent()
Release an instance ofSAAgentV2
from the static HashMap saved inSAAgentV2
.Note: All Service Provider and Service Consumer applications Should call this method in onDestroy of Activity when
SAAgentV2
is no longer needed.- Since:
- 2.6.0
-
onFindPeerAgentsResponse
protected void onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result)
Called when the discovery for matching Accessory Peer Agents is completed. If matching Accessory Peer Agents are found (on the same or multiple remote Accessory Devices), this callback occurs with a list of Peer Agents.Application should handle this callback properly according to result code.
Note: This method is called from the worker thread. Spawn a separate thread if you need to do any heavy lifting in this callback.
- Parameters:
peerAgents
- The list ofSAPeerAgent
instance, if found or null otherwise.result
- The result code. SeePEER_AGENT_FOUND
,FINDPEER_DEVICE_NOT_CONNECTED
,FINDPEER_SERVICE_NOT_FOUND
,FINDPEER_DUPLICATE_REQUEST
.- Since:
- 2.6.0
- See Also:
findPeerAgents()
-
onPeerAgentsUpdated
protected void onPeerAgentsUpdated(SAPeerAgent[] peerAgents, int result)
Called when the status of remote Accessory Peer Agent on a connected remote Accessory Devices changes. This callback is invoked only if you have previously initiated a service discovery request by callingfindPeerAgents()
.If more than one Peer Agents have updated status (on one or more connected Accessory Devices), this callback is invoked with a list of Peer Agents.
Note: Your application can cache the remote Accessory Peer Agents that are notified in the callback with the result code
PEER_AGENT_AVAILABLE
. However, in that case, your application must handle thePEER_AGENT_UNAVAILABLE
result code correctly. By caching the result of a peer agent discovery request, you can skip subsequent Accessory Peer Agents discovery requests until this callback shows with the result codePEER_AGENT_UNAVAILABLE
.Note: This method is called from worker thread. Spawn a separate thread if you need to do any heavy lifting in this callback.
- Parameters:
peerAgents
- The list ofSAPeerAgent
instance representing the remote Accessory Peer Agents.result
- The changed status of the remote Accessory Peer Agent. SeePEER_AGENT_AVAILABLE
,PEER_AGENT_UNAVAILABLE
.- Since:
- 2.6.0
-
onServiceConnectionRequested
protected void onServiceConnectionRequested(SAPeerAgent peerAgent)
Called when a remote Accessory Peer Agent requests a Service Connection.If your application is not running, Samsung Accessory Service Framework invokes your application when a Service Connection request arrives from an Accessory Peer Agent. Your application can handle the Service Connection request from the remote Accessory Peer Agent.
If you want to decide whether to accept or reject a Service Connection request, your application can override this method and call
acceptServiceConnectionRequest(SAPeerAgent)
to accept the Service Connection request, or callrejectServiceConnectionRequest(SAPeerAgent)
to reject it.- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent that requests a Service Connection.- Since:
- 2.6.0
-
onServiceConnectionResponse
protected void onServiceConnectionResponse(SAPeerAgent peerAgent, SASocket socket, int result)
Called when a Service Connection to a remote Accessory Peer Agent is established or failed. This is typically a result ofrequestServiceConnection(SAPeerAgent)
having been called.If a Service Connection is established successfully, the
SASocket
object is passed. It allows the Service Provider or Service Consumer application to send and receive data from a connected Accessory Peer Agent, as well as receive Service Connection related events.Note: This method is called from the worker thread. Spawn a separate thread if you need to do any heavy lifting in this callback. Don't call
super.onServiceConnectionResponse(SAPeerAgent, SASocket, int)
.- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent.socket
- The instance ofSASocket
if the Service Connection is successfully established or null otherwise.result
- The result code corresponding to CONNECTION_* value.- Since:
- 2.6.0
- See Also:
requestServiceConnection(SAPeerAgent)
-
onAuthenticationResponse
protected void onAuthenticationResponse(SAPeerAgent peerAgent, SAAuthenticationToken authToken, int code)
Called when the Accessory Peer Agent authentication is completed.Note: This method may not work properly depending on the firmware version of the accessory device. It is recommended to upgrade accessory device firmware if possible.
- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the authenticated remote Accessory Peer Agent.authToken
- The instance ofSAAuthenticationToken
contains its authentication information.code
- The result code corresponding to AUTHENTICATION_* value.- Since:
- 2.6.0
- See Also:
authenticatePeerAgent(SAPeerAgent)
-
onError
protected void onError(SAPeerAgent peerAgent, java.lang.String errorMessage, int errorCode)
Called when anSAAgentV2
error occurs in Samsung Accessory Service Framework.Note: Implement error handling by overriding this method.
- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent.errorMessage
- The error messageerrorCode
- The error code corresponding toERROR_FATAL
,ERROR_SDK_NOT_INITIALIZED
,ERROR_PERMISSION_DENIED
, orERROR_PERMISSION_FAILED
.- Since:
- 2.6.0
-
findPeerAgents
protected final void findPeerAgents()
Finds matching Accessory Peer Agents.Application should listen for the result of finding Accessory Peer Agent using
onFindPeerAgentsResponse(SAPeerAgent[], int)
callback. If multiple matching Accessory Peer Agents are found, theonFindPeerAgentsResponse(SAPeerAgent[], int)
callback is invoked multiple times, one for each.- Since:
- 2.6.0
-
requestServiceConnection
protected final void requestServiceConnection(SAPeerAgent peerAgent)
Requests a Service Connection with a remote Accessory Peer Agent.The application should listen for the result of a Service Connection request using
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
callback.Note: Ensure the availability of the Accessory Peer Agent before calling this method. This method is typically called in the
onFindPeerAgentsResponse(SAPeerAgent[], int)
callback. You should NOT use the previously cachedSAPeerAgent
instance, as it may be no longer available for making Service Connection with.- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent whom requests Service Connection to.- Throws:
java.lang.IllegalArgumentException
- Thrown if peerAgent argument passed is null or invalid.- Since:
- 2.6.0
-
acceptServiceConnectionRequest
protected void acceptServiceConnectionRequest(SAPeerAgent peerAgent)
Accepts a Service Connection request from the remote Accessory Peer Agent.Application should listen for the result of accepting Service Connection using
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
callback.Note: This method can be called in the implementation of
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
oronServiceConnectionRequested(SAPeerAgent)
callback.- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent whose incoming Service Connection requests.- Throws:
java.lang.IllegalArgumentException
- Thrown if the peerAgent argument passed is null or invalid.- Since:
- 2.6.0
-
rejectServiceConnectionRequest
protected void rejectServiceConnectionRequest(SAPeerAgent peerAgent)
Rejects a Service Connection request from the remote Accessory Peer Agent.The application should listen for the result of a Service Connection rejection using
onServiceConnectionResponse(SAPeerAgent, SASocket, int)
callback.Note: This method can be called in the implementation of
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
oronServiceConnectionRequested(SAPeerAgent)
callback.- Parameters:
peerAgent
- The instance ofSAAgentV2
that represents the remote Accessory Peer Agent whose incoming Service Connection requests.- Throws:
java.lang.IllegalArgumentException
- Thrown if the peerAgent argument is null or invalid.- Since:
- 2.6.0
-
authenticatePeerAgent
protected void authenticatePeerAgent(SAPeerAgent peerAgent)
Authenticates an Accessory Peer Agent.The application should listen for the result of an Accessory Peer Agent authentication using
onAuthenticationResponse(SAPeerAgent, SAAuthenticationToken, int)
callback.Note: This method may not be working properly depending on the firmware version of accessory device. It is recommended to upgrade accessory device firmware if possible.
- Parameters:
peerAgent
- The instance ofSAAgentV2
represents the remote Accessory Peer Agent to be authenticated.- Throws:
java.lang.IllegalArgumentException
- Thrown if the peerAgent argument passed is null or invalid.- Since:
- 2.6.0
-
getServiceProfileId
public java.lang.String getServiceProfileId()
Gets the service profile ID that is declared in the Service Profile XML.- Returns:
- Service profile ID. null if the XML-parsing logic has a problem.
- Since:
- 2.6.0
-
getServiceProfileName
public java.lang.String getServiceProfileName()
Gets the service profile name that is declared in the Service Profile XML.- Returns:
- Service profile name. null if the XML-parsing logic has a problem.
- Since:
- 2.6.0
-
getServiceChannelSize
public int getServiceChannelSize()
Gets the size of the service channel list that is declared in the Service Profile XML.This method can be used to know how many channels in the local agent. So, using this method, you can call
getServiceChannelId(int)
within a valid range of indexes.- Returns:
- The size of the service channel list. -1 if the XML-parsing logic has a problem and return 0 if there is no channel in the Service Profile XML.
- Since:
- 2.6.0
-
getServiceChannelId
public int getServiceChannelId(int index)
Gets the service channel ID at the specific index of the list that is declared in the Service Profile XML.This method can be used for sending messages to peer agents through
SASocket.send(int, byte[])
method. You can use its return value as the service channel ID for the argument ofSASocket.send(int, byte[])
.- Parameters:
index
- The index of channel ID in the service channel list. It starts from index 0- Returns:
- Service channel ID at the given index. -1 if the XML-parsing logic has a problem.
- Since:
- 2.6.0
-
-